-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inheritance.java
52 lines (51 loc) · 1.7 KB
/
Inheritance.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
52
import java.util.Scanner;
class File {
protected String name, itemType, path, owner;
protected int size;
public File(String name, String itemType, String path, String owner, int size) {
this.name = name;
this.itemType = itemType;
this.path = path;
this.owner = owner;
this.size = size;
}
public int getSize() {
return this.size;
}
}
class PNG extends File {
private int width, height;
public PNG(String name, String path, String owner, int size, int width, int height) {
super(name, "PNG", path, owner, size);
this.width = width;
this.height = height;
}
public String getDimension() {
String s = this.width + " x " + this.height;
return s;
}
public void dispProperties() {
System.out.println("Name: " + name + "\nItem Type: " + itemType + "\nPath: " + path + "\nOwner: " + owner + "\nSize: " + size + "\nDimension: " + this.getDimension());
}
}
public class Inheritance {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name, path, owner;
int size, width, height;
System.out.printf("Name: ");
name = sc.next();
System.out.printf("File path: ");
path = sc.next();
System.out.printf("Owner: ");
owner = sc.next();
System.out.printf("File size: ");
size = sc.nextInt();
System.out.printf("Width: ");
width = sc.nextInt();
System.out.printf("Height: ");
height = sc.nextInt();
PNG obj1 = new PNG(name, path, owner, size, width, height);
obj1.dispProperties();
}
}