Program:
class employe
{
protected int emp_no;
protected String name;
protected int salary;
public employe(int empno,String nam,int sal)
{
emp_no=empno;
name=nam;
salary=sal;
}
public void emplo_data()
{
System.out.println("\nEmploy no.="+emp_no);
System.out.println("Name="+name);
System.out.println("Salary="+salary);
}
}
class manager extends employe
{
int reward;
public manager(int empno,String nam,int sal,int p)
{
super(empno,nam,sal);
reward=p;
}
public void managerdata()
{
System.out.println("\nEmploy no.="+emp_no);
System.out.println("Name="+name);
System.out.println("Salary="+salary);
System.out.println("Reward="+reward);
}
}
class scientist extends employe
{
int perks;
public scientist(int empno,String nam,int sal,int s)
{
super(empno,nam,sal);
perks=s;
}
public void scientistdata()
{
System.out.println("\nEmploy no.="+emp_no);
System.out.println("Name="+name);
System.out.println("Salary="+salary);
System.out.println("Perks="+perks);
}
}
class inheritance
{
public static void main(String args[])
{
employe emp= new employe(1,"Varun",20000);
emp.emplo_data();
manager man= new manager(2,"Arun",50000,1000);
man.managerdata();
scientist scient= new scientist(3,"Nithin",60000,5000);
scient.scientistdata();
}
}
Output:
nn@linuxmint ~ $ javac inheritance.java
nn@linuxmint ~ $ java inheritance
Employ no.=1
Name=Varun
Salary=20000
Employ no.=2
Name=Arun
Salary=50000
Reward=1000
Employ no.=3
Name=Nithin
Salary=60000
Perks=5000
nn@linuxmint ~ $
class employe
{
protected int emp_no;
protected String name;
protected int salary;
public employe(int empno,String nam,int sal)
{
emp_no=empno;
name=nam;
salary=sal;
}
public void emplo_data()
{
System.out.println("\nEmploy no.="+emp_no);
System.out.println("Name="+name);
System.out.println("Salary="+salary);
}
}
class manager extends employe
{
int reward;
public manager(int empno,String nam,int sal,int p)
{
super(empno,nam,sal);
reward=p;
}
public void managerdata()
{
System.out.println("\nEmploy no.="+emp_no);
System.out.println("Name="+name);
System.out.println("Salary="+salary);
System.out.println("Reward="+reward);
}
}
class scientist extends employe
{
int perks;
public scientist(int empno,String nam,int sal,int s)
{
super(empno,nam,sal);
perks=s;
}
public void scientistdata()
{
System.out.println("\nEmploy no.="+emp_no);
System.out.println("Name="+name);
System.out.println("Salary="+salary);
System.out.println("Perks="+perks);
}
}
class inheritance
{
public static void main(String args[])
{
employe emp= new employe(1,"Varun",20000);
emp.emplo_data();
manager man= new manager(2,"Arun",50000,1000);
man.managerdata();
scientist scient= new scientist(3,"Nithin",60000,5000);
scient.scientistdata();
}
}
Output:
nn@linuxmint ~ $ javac inheritance.java
nn@linuxmint ~ $ java inheritance
Employ no.=1
Name=Varun
Salary=20000
Employ no.=2
Name=Arun
Salary=50000
Reward=1000
Employ no.=3
Name=Nithin
Salary=60000
Perks=5000
nn@linuxmint ~ $
keep it up.
ReplyDeleteby using same employee class how to get particular employee details suppose i want nithin details only please provide code
ReplyDeleteThanks for sharing this valuable information.
ReplyDeletejava projects in chennai
dotnet projects in chennai
mba projects in chennai
be projects in chennai
ns2 projects in chennai
It is really a great work and the way in which u r sharing the knowledge is excellent.Thanks for helping me to understand inheritance program concepts. As a beginner in java programming your post help me a lot.Thanks for your informative article.java training in chennai
ReplyDeleteInheritance can be defined as the process where one class acquires the properties (methods and fields) of another. With the use of inheritance the information is made manageable in a hierarchical order.
ReplyDeletejava training in chennai | java training in velachery
Inheritance is unidirectional, it is expressed using “is a “ relationship. The car is a Vehicle, but all the vehicles are not a car.
ReplyDeleteVery informative ..i suggest this blog to my friends..Thank you for sharingjava training in chennai | chennai's no.1 java training in chennai | best java institute in chennai
Good work sir, Thanks for the proper explanation about Inheritance . I found one of the good resource related JAVA and OOPS concepts. It is providing in-depth knowledge on JAVA and OOPS. which I am sharing a link with you where you can get more clear on JAVA and OOPS. To know more Just have a look at this link
ReplyDeleteJava Tutorial
Class and object
Inheritance
Polymorphism
Abstraction
Encapsulation
mm
Good work sir, Thanks for the proper explanation about Inheritance . I found one of the good resource related JAVA and OOPS concepts. It is providing in-depth knowledge on JAVA and OOPS. which I am sharing a link with you where you can get more clear on JAVA and OOPS. To know more Just have a look at this link
ReplyDeleteJava Tutorial
Class and object
Inheritance
Polymorphism
Abstraction
Encapsulation
n
I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.
ReplyDeletedatascience training in chennai
I was recommended this web site by means of my cousin.
ReplyDeleteI am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!
selenium training in Chennai
selenium training in Tambaram
selenium training in Velachery
selenium training in Omr
selenium training in Annanagar
Great collection and thanks for sharing this info with us. Waiting for more like this.
ReplyDeleteDevOps Training in Chennai
DevOps Certification in Chennai
AWS Training in Chennai
Data Science Course in Chennai
ccna course in Chennai
R Programming Training in Chennai
Angularjs Training in Chennai
RPA Training in Chennai
Blue Prism Training in Chennai
ReplyDeleteNice article and thanks for sharing with us. Its very informative
Tableau Training in Hyderabad
This comment has been removed by the author.
ReplyDeleteI appreciate this blog's ability to provide information on such an important subject
ReplyDeletePTE Institute in ambala
Best IELTS Institute in Ambala
IELTS Coaching in Ambala
city
Spouse visa consultants in Ambala
Fantastic article post.Really thank you! Awesome.
ReplyDeletedot net training
dot net online training
Great Post!!! Thanks for sharing this great post.
ReplyDeleteUses of Java
Java Applications
Nice Post!!! gratitude for imparting this post to us.
ReplyDeleteAndroid Course in Chennai
Android Online Course
Android Course in Bangalore
Nice article. Keep up with your writing.
ReplyDeleteJava Classes in Nagpur
informative blog, keep posting java course in satara
ReplyDeleteThanks for sharing this blog with us. It was really interesting.
ReplyDeleteJava course in Pune