11) Create an abstract class Person. Derive two classes Employee and Worker from it. Use proper method to accept and display the details for the same. The fields of Employee are Emp_no,Emp_name and address. Similar fields for worker are name and working hours.


abstract class Person
{
void accept() { }
abstract void display();

}
class Employee extends Person
{
int Emp_no;
String Emp_name,add;

Employee()
{
Emp_no=0;
Emp_name=null;
add=null;
}
void accept(int no,String n,String a)
{
Emp_no=no;
Emp_name=n;
add=a;
}
void display()
{
System.out.println(“Emp_no= “+Emp_no);
System.out.println(“Emp_name= “+Emp_name);
System.out.println(“Address= “+add);
}
}
class Worker extends Person
{
int wh;
String name;
Worker()
{
wh=0;
name=null;
}
void accept(String n,int h)
{
wh=h;
name=n;
}
void display()
{
System.out.println(“Worker’s name= “+name);
System.out.println(“Working hour= “+wh);
}
}

class PerEmpWor
{
public static void main(String args[])
{
Person p1; // abstract class

Employee e1=new Employee();
e1.accept(201,”Raj”,”Pune”); //parameter as Emp_no,Emp_Name,address)

Worker m1=new Worker();
m1.accept(“Raj”,8); //parameter as(Name,WorkingHours)

System.out.println(“\n———–Employee———–”);
p1=e1;
p1.display();

System.out.println(“\n———–Worker———–”);
p1=m1; p1.display();
}}
11) Create an abstract class Person. Derive two classes Employee and Worker from it. Use proper method to accept and display the details for the same. The fields of Employee are Emp_no,Emp_name and address. Similar fields for worker are name and working hours.
abstract class Person
{
void accept() { }
abstract void display();

}
class Employee extends Person
{
int Emp_no;
String Emp_name,add;

Employee()
{
Emp_no=0;
Emp_name=null;
add=null;
}
void accept(int no,String n,String a)
{
Emp_no=no;
Emp_name=n;
add=a;
}
void display()
{
System.out.println(“Emp_no= “+Emp_no);
System.out.println(“Emp_name= “+Emp_name);
System.out.println(“Address= “+add);
}
}
class Worker extends Person
{
int wh;
String name;
Worker()
{
wh=0;
name=null;
}
void accept(String n,int h)
{
wh=h;
name=n;
}
void display()
{
System.out.println(“Worker’s name= “+name);
System.out.println(“Working hour= “+wh);
}
}

class PerEmpWor
{
public static void main(String args[])
{
Person p1; // abstract class

Employee e1=new Employee();
e1.accept(201,”Raj”,”Pune”); //parameter as Emp_no,Emp_Name,address)

Worker m1=new Worker();
m1.accept(“Raj”,8); //parameter as(Name,WorkingHours)

System.out.println(“\n———–Employee———–”);
p1=e1;
p1.display();

System.out.println(“\n———–Worker———–”);
p1=m1; p1.display();
}}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s