0% found this document useful (0 votes)
7 views

MainClass1 Java

Uploaded by

Varsha Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

MainClass1 Java

Uploaded by

Varsha Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

public class Demo {

public static void main(String[] args) {

ArrayList<Employee> er1 = new ArrayList()<>;


er1.add(new Engineer(8,"IT","Varsha",20, 80000, 1));
er1.add(new Engineer(8,"IT","mayur",20, 80000, 2));
er1.add(new Engineer(8,"IT","shaa",20, 90000, 3));
er1.add(new Teacher("math","it","shreyash",21,3000,4));
er1.add(new Teacher("science","it","prasahnnt",24,5000,4));

er1.sort(new Comparator <Employee> ()) {


public int compare(Employee e1, Employee e2){
return e1.getSalary - e2.getSalary;
}

});

System.out.println("Sorted Output is ");


System.out.println(er1);

}
}

class Person {
protected String name;
protected int age;
public person(String name,int age) {
this.name=name;
this.age=age;
}
public String toString() {
return " "+this.name+" "+this.age;
}
}

class Employee extends Person {


private int salary;
private int id;
public person(String name,int age,int salary,int id) {
super(name,age);
this.salary=salary;
this.id=id;
}
public int getSalary() {
return salary;
}
public String toString() {
return super.toString+" "+thisid+" "+this.salary;
}
}
class Teacher extends Employee {
private String subject;
private String dept1;
public person(String subject,String dept1,String name,int age,int salary,int
id) {
super(name,age,salary,dept);
this.subject=subject;
this.dept1=dept1;
}
public String toString() {
return super.toString+" "+this.subject+" "+this.dept1;
}

class Engineer extends Employee {


private int exp1;
private String dept2;
public person(int exp1;,String dept1,String name,int age,int salary,int id) {
super(name,age,salary,dept);
this.exp1=exp1;
this.dept2=dept2;
}
public String toString() {
return super.toString+" "+this.exp1+" "+this.dept2;
}
}
class Pricipal extends Teacher {
private int exp2;
public person(int exp2,String subject,String dept1,String name,int age,int
salary,int id) {
super(name,age,salary,dept,subject,dept1);
this.exp2=exp2;
}
public String toString() {
return super.toString+" "+this.exp2;
}
}

You might also like