Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Java Beginners Multilevel Inheritance in java


Share on Google+Share on Google+

Multilevel Inheritance in java

We are going to discuss about multilevel inheritance in java.

Multilevel Inheritance in java

We are going to discuss about multilevel inheritance in java. The Multilevel inheritance is inherit of classes more than two classes. We use multilevel inheritance to create one-to-one ladder. "super" keyword is used to inherit features of a superclass into subclass in Multilevel inheritance. We can access properties of all classes. we have used extend keyword, extend keyword is a inherit  parent class to subclass. Java, every class is a subclass of  java.lang.Object.

Example of Multilevel Inheritance in java

package Inheritance;
class Animal
        private int cow;
        private String bear;
        public void setstud(int no,String name)
        	cow = no;
        	bear = name;
        public void putstud()
                System.out.println("Eat of Animal milk: " + cow);
                System.out.println("Eat of Animal gras : " + bear);
class test extends Animal
        protected int test1,test2;
        public void settest(int k,int l)
        	   test1 = k;
                test2 = l;
        public void puttest()
                System.out.println("test1 : " + test1);
                System.out.println("test2 : " + test2);
class MultilevelExample extends test
        private int total;
        public void calc()
                total = test1 + test2;
        public void puttotal()
               System.out.println("Total : " + total);
        public static void main(String args[])
        	MultilevelExample f = new MultilevelExample();


Download Source Code


If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 31, 2013

Related Tutorials

Discuss: Multilevel Inheritance in java  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image