Program with Concept of Inheritance with Method Overriding

Develop a program to implement the concept of inheritance with method overriding.

Program:

import java.util.Scanner;

class ABC

{
        int i; 

        int j;

        void accept()

       {

             Scanner sc=new Scanner(System.in);

             System.out.println("Enter the value of i:");

             i=sc.nextInt();

             System.out.println("Enter the value of j:");

              j=sc.nextInt();

          }

void display()

         {

              System.out.println("Value of i is "+i);

              System.out.println("Value of j is "+j);

          }

}

class XYZ extends ABC

{

           int k;

           ABC obj1=new ABC();

           void accept()

           {

                   super.accept();

                   Scanner ob=new Scanner(System.in);

                   System.out.println("Enter the value of k:");

                   k=ob.nextInt();

              }

              void display()

             {

                     super.display();

                     System.out.println("The value of k is "+k);

             }

}

class Inheritance

{

              public static void main(String args[])

              {

                      XYZ obj=new XYZ();

                      obj.accept();

               }

}

Java Tips

See also

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.