Inheritance Program in Java

Advertisements

Prev Tutorial Next Tutorial

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


Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements