What is Inheritance in Java? Give me an example




Asked on February 03, 2015
What is Inheritance in Java? Give me an example


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











©2024 concretepage.com | Privacy Policy | Contact Us