Pages

Saturday, December 14, 2013

Java - Inheritance


Acquing the properties and behaviour of super class from a sub class.

Example:
 class Car{…………}                                                                    SUPER CLASS
class  Maruthi extends Car{………………………..}                     SUB CLASS


  • Sub class did not have multiple super class
  •  Super class did have multiple sub class
  • The sub class can access the super class method 
  • But Super class cannot access the Sub class method. 

SUPER CLASS:
class Difference {
       
          public static void main(String[] args) {
                   static void display() {
            System.out.println("Programming is amazing.");
          }
       
}
 


 SUB CLASS:
public class Sub extends Difference{
    public static void main(String[] arg)
    {   
        display();
    int a=8,c=9;
    System.out.println(a+c);
    }
   
}






















No comments:

Post a Comment