Skip to content

Instantly share code, notes, and snippets.

@Arjun2002tiwari
Created December 14, 2021 19:11
Show Gist options
  • Save Arjun2002tiwari/4dd264c86413e25c497b7a516881309b to your computer and use it in GitHub Desktop.
Save Arjun2002tiwari/4dd264c86413e25c497b7a516881309b to your computer and use it in GitHub Desktop.
abstract class Marks{
abstract double getPercentage();
}
class A extends Marks{
int sub1,sub2,sub3;
int sum;
double per;
A(int sub1,int sub2,int sub3) {
this.sub1 = sub1;
this.sub2 = sub2;
this.sub3 = sub3;
}
double getPercentage(){
sum=sum+sub1+sub2+sub3;
per = (sum*100)/300;
return per;
}
}
class B extends Marks{
int sub1,sub2,sub3;
int sum=0;
double per;
B(int sub1,int sub2,int sub3) {
this.sub1 = sub1;
this.sub2 = sub2;
this.sub3 = sub3;
}
double getPercentage(){
sum=sum+sub1+sub2+sub3;
return sum;
}
}
public class Main2 {
public static void main(String[] args) {
A obj = new A(50,50,50);
double ans1 = obj.getPercentage();
System.out.println(ans1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment