-
Notifications
You must be signed in to change notification settings - Fork 6
/
InnerClassDemo.java
43 lines (36 loc) · 1.12 KB
/
InnerClassDemo.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
package com.sjcet.oopdemo;
class CPU {
double price;
// nested class
class Processor{
// members of nested class
double cores;
String manufacturer;
double getCache(){
return 4.3;
}
}
// nested protected class
class RAM{
// members of protected nested class
double memory;
String manufacturer;
double getClockSpeed(){
return 5.5;
}
}
}
public class InnerClassDemo {
public static void main(String[] args) {
// create object of Outer class CPU
CPU cpu = new CPU();
cpu.price = 15000;
System.out.println("CPU Price = "+cpu.price);
// create an object of inner class Processor using outer class
CPU.Processor processor = cpu.new Processor();
// create an object of inner class RAM using outer class CPU
CPU.RAM ram = cpu.new RAM();
System.out.println("Processor Cache = " + processor.getCache());
System.out.println("Ram Clock speed = " + ram.getClockSpeed());
}
}