JAVA
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
/* No. It can also be public/protected depends on how it's to be used. For instance in the following example with public, we can have robots that don't have brain as we don't instantiate brain in the constructor of robot. Later, we can add a brain to them, make them think and make them stop thinking.
*/
public class Robot {
int id;
Robot(int i) {
id = i;
}
public class Brain {
public void think() {
System.out.println(id + " started thinking...");
}
public void stopThinking()
{
System.out.println(id + " Stopped thinking");
}
}
}
public class Program {
public static void main(String[] args) {
Robot r = new Robot(1);
Robot.Brain b = r.new Brain();
/* mình không thể hiểu nổi cú pháp
" Robot.Brain" ( nó là 2 class) và
" r.new" Brain();
why "Robot.Brain" they are both the name of two classes ( one inner class, and another outer one).
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run