-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu
58 lines (48 loc) · 1.4 KB
/
cpu
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
57
Question:
Create CPU with attribute price. Create inner class Processor (no. of cores, manufacturer) and static
nested class RAM (memory, manufacturer). Create an object of CPU and print information of Processor and RAM.
CODE:
public class cpu{
int price;
class processor{
int cores;
String producer;
processor(int noC, String manu){
cores=noC;
producer=manu;
}
void display(){
System.out.println("\nProcessor info");
System.out.println("No. of Cores = "+cores);
System.out.println("Manufacturer = "+producer+"\n");
}
}
static class ram{
int mem;
String manuf;
ram(int memory,String producer ){
mem=memory;
manuf=producer;
}
void display(){
System.out.println("\nRAM info");
System.out.println("Memory = "+mem+" GB");
System.out.println("Manufacturer = "+manuf+"\n");
}}
public static void main(String[] args) {
cpu.ram obj1= new cpu.ram(8,"Intel");
cpu obj2 = new cpu();
cpu.processor obj3 = obj2.new processor(8,"Samsung");
obj1.display();
obj3.display();
}
}
OUTPUT
mlm@mlm-desktop:~/Desktop/Rojin/java$ javac cpu.java
mlm@mlm-desktop:~/Desktop/Rojin/java$ java cpu
RAM info
Memory = 8 GB
Manufacturer = Intel
Processor info
No. of Cores = 8
Manufacturer = Samsung