-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathComposition of class in Java
56 lines (49 loc) · 1.26 KB
/
Composition of class in 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
53
54
55
56
// "static void main" must be defined in a public class.
class OS {
String name;
int version;
OS(String name, int version) {
this.name = name;
this.version = version;
}
@Override
public String toString() {
return "\nOS details\n name= "+name+", version= "+version;
}
}
class CPU {
String name;
int RAM;
int ROM;
CPU(String name, int RAM, int ROM) {
this.name = name;
this.RAM = RAM;
this.ROM = ROM;
}
@Override
public String toString() {
return "\nCPU details\n name= "+name+", RAM= "+RAM+", ROM= "+ROM;
}
}
public class Computer {
String name;
int price;
OS os;
CPU cpu;
Computer(String name, int price, OS os) {
this.name = name;
this.price = price;
this.os = os;
}
@Override
public String toString() {
return "\nComputer Details\n name= "+name+", price= "+price+", OS= "+os+", CPU= "+cpu;
}
public static void main(String[] args) {
OS osObj = new OS("Windows", 10);
CPU cpuObj = new CPU("Inter Core i-7", 16, 512);
System.out.println(cpuObj);
Computer computer = new Computer("Dell", 32000, osObj);
System.out.println(computer);
}
}