-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathInheritanceExample.java
64 lines (43 loc) · 1.39 KB
/
InheritanceExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Marks{
public int getmarks(int hindi, int english, int maths , int science){
int total = hindi + english + maths + science;
System.out.println("marks in hindi: "+hindi);
System.out.println("marks in english: "+english);
System.out.println("marks in maths: "+maths);
System.out.println("marks in science: "+science);
System.out.println("Total marks: "+total);
return total;
}
}
class Percentage extends Marks{
int total = getmarks(90, 80, 70, 60);
public float getPercentage(){
float percentage = (total/400.0f)*100;
System.out.println("Percentage: "+percentage);
return percentage;
}
}
class Result extends Percentage{
float percentage;
public Result() {
percentage = getPercentage();
if(percentage > 80 && percentage <= 100){
System.out.println("Grade A");
}
else if(percentage > 60 && percentage <= 80){
System.out.println("Grade B");
}
else if(percentage > 40 && percentage <= 60){
System.out.println("Grade C");
}
else{
System.out.println("Fail");
}
}
}
public class InheritanceExample {
public static void main(String[] args) {
Result r = new Result();
r.getPercentage();
}
}