-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinheritanceEX4.java
More file actions
70 lines (69 loc) · 1.63 KB
/
inheritanceEX4.java
File metadata and controls
70 lines (69 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package Encapsulation;
class Person1
{
public String name;
public int age;
public Person1(String name,int age)
{
this.name = name;
this.age = age;
}
public void displayperson()
{
System.out.println("Name : "+ name);
System.out.println("Age : "+ age);
}
}
class Employee1 extends Person1
{
public int id;
public double salary;
public Employee1(String name,int age,int id,double salary)
{
super(name,age);
this.id = id;
this.salary = salary;
}
void displayemloyee()
{
System.out.println("Employee ID : "+id);
System.out.println("Salary : "+salary);
}
}
class Student2 extends Person1
{
public int rollno;
public int marks;
public Student2(String name,int age,int rollno,int marks)
{
super(name,age);
this.rollno = rollno;
this.marks = marks;
}
void displaystudent()
{
System.out.println(" Roll No : "+rollno);
System.out.println(" Marks : "+marks);
}
}
public class inheritanceEX4
{
public static void main(String[]args)
{
System.out.println("====================");
System.out.println("person");
Person1 P = new Person1("Ramu", 33);
P.displayperson();
System.out.println("=====================");
System.out.println("Employee");
Employee1 E = new Employee1("Raj",22,101,22333);
E.displayperson();
E.displayemloyee();
System.out.println("=====================");
System.out.println("Student");
Student2 S = new Student2("Raj",17,22,95);
S.displayperson();
S.displaystudent();
System.out.println("=====================");
}
}