-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuperkey.java
More file actions
34 lines (33 loc) · 794 Bytes
/
superkey.java
File metadata and controls
34 lines (33 loc) · 794 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 superkey {
public static void main(String[]args)
{
//super = used to calll parent constructor and initialize attributes
women w1=new women("Tanya",19);
accessory a1=new accessory("Tanya",19,"gold");
w1.show();
a1.show();
}
}
class women{
String name;
int age;
women(String name,int age){
this.name=name;
this.age=age;
}
void show()
{
System.out.println(this.name+" is "+this.age);
}
}
class accessory extends women{
String necklace;
accessory(String name,int age,String necklace){
super(name,age);
this.necklace=necklace;
}
void show()
{
System.out.println(this.name+" is "+this.age+" and wears "+this.necklace);
}
}