JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Robot {
int id;
Robot(int i) {//calling the constructor
id = i;//assigning variable
Brain b = new Brain();//declaring object
b.think();//calling a method to be applied on object b of class Brain
}
private class Brain {//declaring an inner class
public void think() {//calling the method to define it
System.out.println(id + " is thinking");//defining the method
}
}
}
public class Program {//inner class
public static void main(String[] args) {
Robot r = new Robot(1);//calling the constructor
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run