-
Notifications
You must be signed in to change notification settings - Fork 11
/
Implementing-Class-Concept-in-java
38 lines (37 loc) · 1.15 KB
/
Implementing-Class-Concept-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
// 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
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();
}
}