-
Notifications
You must be signed in to change notification settings - Fork 2
/
Super.java
51 lines (41 loc) · 1022 Bytes
/
Super.java
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
import java.util.*;
// Super Keyword in Java
class Human {
String name = "No Name";
boolean isMortal = true;
String species = "Human";
Human() {
System.out.println("Human Constructor");
}
void breathe() {
System.out.println("Human is breathing");
}
}
class Person extends Human {
String name;
Person(String name) {
super();
this.name = name;
System.out.println("Person Constructor");
}
void breathe() {
super.breathe();
System.out.println("Person is breathing");
}
void changeSpecies() {
super.species = "Cyborg";
}
void printName() {
System.out.println("Name: " + name);
}
}
public class Super {
public static void main(String[] args) {
Person p = new Person("Anurag");
p.breathe();
System.out.println("Is Human Species: " + p.species);
p.changeSpecies();
System.out.println("Species: " + p.species);
p.printName();
}
}