JAVA PROGRAM CÓ 2 INNER CLASSES.
class Inner1 { … } and class Inner2 { … }
1- Compiler của Ideone.com phải dùng outer class là class Main.
public class Main {
String outerStr = " String in the class outer : THÂN CHÀO QUÝ BAN !\n" ;
class Inner1 {
String inner1Str = " String in the class Inner1 : \n" ;
String display1(String parameter) {
return outerStr+ inner1Str + parameter ; }
}
public static void main(String[] args) {
Main outer = new Main();
outer.run() ;
Main outer1 = new Main();
outer1.go() ; }
void run() {
Inner1 local = new Inner1();
System.out.println(local.display1(" Hola Amigaso ! COMMO ESTA ?"));
}
void go() {
Inner2 in2 = new Inner2();
System.out.println(in2.display2("Hello Friends ! HOW ARE YOU ?"));
}
class Inner2 {
String inner2Str = " String in the class Inner2 :\n" ;
String display2(String parameter) {
return inner2Str + parameter ; }
}
}
Output.
SUCCESS
String in the class outer : THÂN CHÀO QUÝ BAN !
String in the class Inner1 :
Hola Amigaso ! COMMO ESTA ?
String in the class Inner2 :
Hello Friends ! HOW ARE YOU ?
2- Compiler của Rextester.com
class Rextester {
String outerStr = " String in the class outer : THÂN CH̀ÀO QUÝ BAN ! \n" ;
class Inner1 {
String inner1Str = " String in the class Inner1 :\n" ;
String display1(String parameter) {
return outerStr + inner1Str + parameter ; }
}
public static void main(String[] args) {
Rextester outer = new Rextester();
outer.run() ;
Rextester outer1 = new Rextester();
outer1.go() ; }
void run() {
Inner1 local = new Inner1();
System.out.println(local.display1(" Hola Amigaso ! COMMO ESTA ?"));
}
void go() {
Inner2 in2 = new Inner2();
System.out.println(in2.display2("Hello Friends ! HOW ARE YOU ?"));
}
class Inner2 {
String inner2Str = " String in the class Inner2 :\n" ;
String display2(String parameter) {
return inner2Str + parameter ; }
}
}
output.
Compilation time: 0.82 sec, absolute running time: 0.14 sec,
cpu time: 0.07 sec, memory peak: 23 Mb, absolute service time: 0.97 sec
String in the class outer : THÂN CHÀO QUÝ BAN !
String in the class Inner1 :
Hola Amigaso ! COMMO ESTA ?
String in the class Inner2 :
Hello Friends ! HOW ARE YOU ?