-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverriding.java
More file actions
34 lines (33 loc) · 775 Bytes
/
overriding.java
File metadata and controls
34 lines (33 loc) · 775 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
public class overriding {
public static void main(String[]args)
{
//method overriding=when a subclass provides its own implementation
// of a method that is already defined.
//allows for code reusability and give specific implementation
person pr = new person();
man m=new man();
girl g=new girl();
pr.show();
m.show();
g.show();
}
}
class person{
void show()
{
System.out.println("The person is he.");
}
}
class man extends person{
void show()
{
System.out.println("The person is he.");
}
}
class girl extends person{
@Override
void show()
{
System.out.println("The person is she.");
}
}