Single level inheritance program in Java
//Java program for single level inheritance class Abaseclass //Base class definition { void show() //Base class show method { System.out.println("This is the show method of Base class 'A'"); } } class Bderivedclass extends Abaseclass //Derived class definition { void show() //Derived class show method { System.out.println("This is the show method of Base class 'B'"); } } class singlelevelmainclass //Main class from where the execution will start { public static void main(String args[]) // Main method of main class { Abaseclass a = new Abaseclass(); // Object creation of base class Bderivedclass b = new Bderivedclass(); // Object creation of derived class a.show(); //base class method show is called by the object of base class b.show(); //derived class method show is called by the object of derived class } } //Save the above code as singlelevelmainclass.java //Output of the above code : //This is the show method of Base class 'A' //This is the show method of Base class 'B'
0 comments:
Post a Comment