Inheritance Program in Java
Advertisements
Inheritance Example in Java
Inheritance is the concept of reusability. Most important real life example of inheritance is father and son, all properties of father are inherited by his son. Here we write code for Inheritance using Java programming.
Inheritance Example in Java
class Faculty { float salary=30000; } class Science extends Faculty { float bonous=2000; public static void main(String args[]) { Science obj=new Science(); System.out.println("Salary is:"+obj.salary); System.out.println("Bonous is:"+obj.bonous); } }
Output
Salary is: 30000.0 Bonous is: 2000.0
Syntax to compile and run java program
Syntax
for compile -> c:/>javac Faculty.java for run -> c:/>java Faculty
For more derails about Inheritance in Java
Google Advertisment