-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathInheritance.java
More file actions
42 lines (33 loc) · 928 Bytes
/
Inheritance.java
File metadata and controls
42 lines (33 loc) · 928 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
package code;
class Stationary{
String company;
Stationary(String company){
this.company=company;
}
public void printdetails() {
System.out.println("Pen company : "+this.company);
}
}
class Pen extends Stationary{
String color;
int quantity;
public Pen(String company,String color,int quantity){
super(company);
this.color=color;
this.quantity=quantity;
}
public void printdetails() {
super.printdetails();
System.out.println("Pen color : "+this.color+" and quantity is "+this.quantity);
}
}
public class Inheritance {
public static void main(String[] args) {
// TODO Auto-generated method stub
Pen p1=new Pen("Reynolds","Blue",2);
//p1.color="Blue";
//System.out.print(p1.printdetails("Reynolds")+p1.printdetails("Blue",2));
p1.printdetails();
//without constructor p1.printdetails(reynolds) again p1.printdetails(blue,2)
}
}