Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • INHERITANCE IN JAVA

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 294
    Comment on it

    Inheritance is a process where sub class have same properties then its super class. In this process sub class acquire all the characteristics of its super class. By using inheritance we can manage information in hierarchical manner.

    The class which take properties of other class is called subclass and the one whose properties has been taken is called super class.

    By using extends keyword properties of a class get inherit .

    Syntax

    class car {
       .....
       .....
    }
    
    class maruti extends car  {
       .....
       .....
    
    }
    

    eg:-

    class BaseClass
    {
        public void show()
        {
            System.out.println("HELLO");
        }
    }
    public class SubClass extends BaseClass {
        public void print()
        {
            System.out.println("HI");
        }
        public static void main(String[] args)
        {
           SubClass obj = new SubClass();
            obj.print();                                //method of Child class
            obj.show();                        //method of Parent class 
        }
    }
    

    OUTPUT

    HI
    HELLO
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: