Home  >  Forum  >  Core Java
Post New Query

What is Inheritance in Java? Give me an example


joined on
February 03,2015
Asked on February 03,2015
What is Inheritance in Java? Give me an example
joined on
March 15,2013
Replied on February 03,2015

Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.
Types of Inheritance
1- single 
2- multilevel
3- hierarchical

Note: Java does not support multiple inheritance

// Example of Inheritance

package programs;

class emp{
int sal=1000;
}
class Programer extends emp{
int bonus= 500;
    public static void main(String[] args) {
Programer pmr= new Programer();
    System.out.println("Salary of programer="+pmr.sal);
System.out.println("Bonus of programer="+pmr.bonus);
}

}
 

Write Answer









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us