-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperKeyWord.java
More file actions
58 lines (51 loc) · 1.25 KB
/
SuperKeyWord.java
File metadata and controls
58 lines (51 loc) · 1.25 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
public class Main{
public static void main(String[] args) {
Hero hero = new Hero("Batman",42,"Money");
System.out.println("Power is : "+hero.power);
System.out.println("\n");
// Another way of doing this is by using toString() method.
Hero1 hero1 = new Hero1("SuperMan",100,"Lazer Vision");
System.out.println(hero1.toString());
}
}
class Person{
String name;
int age;
Person(String name, int age)
{
System.out.println("Name is : "+name);
System.out.println("Age is : "+age);
}
}
class Hero extends Person{
String power;
Hero(String name,int age,String power)
{
super(name,age);
this.power=power;
}
}
class Person1{
String name;
int age;
Person1(String name, int age)
{
this.name=name;
this.age=age;
}
public String toString()
{
return name+"\n"+age+"\n";
}
}
class Hero1 extends Person1{
String power;
Hero1(String name,int age,String power){
super(name,age);
this.power=power;
}
public String toString()
{
return super.toString()+power; // Calls the parent toString() method
}
}