-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.java
More file actions
44 lines (37 loc) · 858 Bytes
/
Inheritance.java
File metadata and controls
44 lines (37 loc) · 858 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
43
44
public class Inheritance {
public static void main(String[] args)
{
Base obj = new Base("Test1",14);
System.out.println(obj.toString());
Derived obj2 = new Derived("Test2",12,"Pokemon-Trainer");
System.out.println(obj2.toString());
}
}
public class Base
{
public String name;
public int age;
public Base(String name,int age)
{
this.name = name;
this.age = age;
}
public String toString()
{
return("Name is " + name + "\nAge is " + age);
}
}
public class Derived extends Base
{
public String job;
public Derived(String name,int age,String job)
{
super(name,age);
this.job = job;
}
@Override
public String toString()
{
return (super.toString() + "\nJob is " + job);
}
}