Skip to content

Commit 7601810

Browse files
committed
updated the solutions
1 parent 56f8225 commit 7601810

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

LAB2/booleanTest.java

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ public static void main(String[] args){
77
System.out.println("b is "+ b);
88
System.out.println("b is " + !b);
99

10-
// TODO :Complete the Program
11-
1210
if(b) System.out.println("This is executed.");
1311
b=false;
1412
if(b) System.out.println("This is not executed.");

LAB4/InheritanceDemo.java

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*5. Create a class student with instance variables roll_no and two methods to read and display the
2+
roll_no. Then create another class Test that inherits class student, consisting of its own instance
3+
variables to hold the marks of two subjects and also methods to read and display the marks.
4+
Finally, create another class Result which inherits class Test. It also has its own instance variable
5+
total to hold the total of two marks scored by the student. Similarly, it has methods to calculate
6+
and display the total. Create some instance of above classes and demonstrate inheritance. */
7+
8+
/*
9+
* author: @pray3m
10+
*/
11+
12+
class Student{
13+
int rollNo;
14+
Student(int rollNo){
15+
this.rollNo=rollNo;
16+
}
17+
18+
void display(){
19+
System.out.println("Roll No: "+rollNo);
20+
}
21+
}
22+
23+
class Test extends Student{
24+
int marks1,marks2;
25+
26+
Test(int roll,int marks1,int marks2){
27+
super(roll);
28+
this.marks1=marks1;
29+
this.marks2=marks2;
30+
}
31+
32+
void displayMarks(){
33+
System.out.printf("The marks \n\t Sub 1 :%d \n\t Sub 2 : %d",marks1,marks2);
34+
}
35+
}
36+
37+
class Result extends Test{
38+
int total=0;
39+
40+
Result(int roll,int marks1, int marks2){
41+
super(roll, marks1, marks2);
42+
total=marks1+marks2;
43+
}
44+
45+
int calcTotal(){
46+
return total;
47+
}
48+
49+
void displayResult(){
50+
super.display();
51+
super.displayMarks();
52+
System.out.println("\n The total marks is: "+total);
53+
}
54+
}
55+
56+
57+
public class InheritanceDemo{
58+
public static void main(String[] args) {
59+
Result s1=new Result(1,56,76);
60+
s1.displayResult();
61+
}
62+
}
63+
64+

LAB4/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ super, abstract class and method.
1212
- [Q.N 2](https://github.com/pray3m/JavaPrograms/blob/main/LAB4/MultilevelInheritance.java)
1313
- [Q.N 3](https://github.com/pray3m/JavaPrograms/blob/main/LAB4/HierarchicalInheritance.java)
1414
- [Q.N 4*](https://github.com/pray3m/JavaPrograms/blob/main/LAB4/BoxDemo.java)
15-
- [Q.N 5*](https://github.com/pray3m/JavaPrograms/blob/main/LAB4/BoxDemo.java)
15+
- [Q.N 5](https://github.com/pray3m/JavaPrograms/blob/main/LAB4/InheritanceDemo.java)
1616
- [Q.N 6](https://github.com/pray3m/JavaPrograms/blob/main/LAB4/SuperKey.java)
1717
- [Q.N 7](https://github.com/pray3m/JavaPrograms/blob/main/LAB4/superMethod.java)
1818
- [Q.N 8*](https://github.com/pray3m/JavaPrograms/blob/main/LAB4/BoxDemo.java)

0 commit comments

Comments
 (0)