WAP to implement inheritance and overloading methods in java

717 views

Published on

WAP to implement inheritance and overloading methods

Published in: Education, Technology, Business
  • Be the first to comment

  • Be the first to like this

WAP to implement inheritance and overloading methods in java

  1. 1. //Ques. 10 WAP to implement inheritance and overloading methods. importjava.util.*; class mob { privateint roll; private String name; Scanner x=new Scanner(System.in); public void getmob( ) { System.out.print("n Enter Roll No. = "); roll=x.nextInt( ); System.out.print("n Enter Name = "); name=x.next( ); } public void putmob( ) { System.out.println("n Roll No. : "+roll); System.out.println("n Name: "+name); } } class drive extends mob { publicintp,c,m; voidgetdrive( ) {
  2. 2. getmob( ); Scanner in=new Scanner(System.in); System.out.print("n Marks in Physics: "); p=in.nextInt( ); System.out.print(" Marks in Chemistry: "); c=in.nextInt( ); System.out.print(" Marks in Maths: "); m=in.nextInt( ); } public void putdrive( ) { putmob( ); System.out.println("n Marks: "+p+", "+c+", "+m); } } class pen extends drive { privateint tm; voidgetresult( ) { getdrive( ); tm=p+c+m; } voidputresult( ) { putdrive( );
  3. 3. System.out.println(" Total Marks: "+tm); } } class computer { public static void main(String arg[ ]) { pen s=new pen( ); s.getresult( ); s.putresult( ); } } OUTPUT:-

×