-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.java
More file actions
42 lines (32 loc) · 780 Bytes
/
Inheritance.java
File metadata and controls
42 lines (32 loc) · 780 Bytes
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
class Person {
protected String name;
public void walk(){
System.out.println(name+" is walking");
}
public void eat(){
System.out.println(name+ " is eating");
}
}
class Teacher extends Person{
public void teach(){
System.out.println(name+ " is Teaching");
}
}
class Singer extends Person{
public void Sing(){
System.out.println(name+ " is singing");
}
}
public class Inheritance {
public static void main(String args[]) {
Teacher t=new Teacher();
t.name="Shivani";
t.eat();
t.walk();
t.teach();
Singer s=new Singer();
s.name="Nikita";
s.Sing();
s.eat();
}
}