class Mug{
Mug(int marker){
System.out.println("Cup(" + marker + ")");
}
void fun(int marker){
System.out.println("fun(" + marker + ")");
}
}
class Mugs{
Mug c1;
Mug c2;
{
c1 = new Mug(1);
c2 = new Mug(2);
System.out.println("c1 & c2 initialized");
}
Mugs(){
System.out.println("Mugs()");
}
}
public class Property {
public static void main(String[] args) {
System.out.println("Creating new Mugs in main");
Mugs m = new Mugs();
m.c1.fun(1);
m.c2.fun(2);
}
Mug(int marker){
System.out.println("Cup(" + marker + ")");
}
void fun(int marker){
System.out.println("fun(" + marker + ")");
}
}
class Mugs{
Mug c1;
Mug c2;
{
c1 = new Mug(1);
c2 = new Mug(2);
System.out.println("c1 & c2 initialized");
}
Mugs(){
System.out.println("Mugs()");
}
}
public class Property {
public static void main(String[] args) {
System.out.println("Creating new Mugs in main");
Mugs m = new Mugs();
m.c1.fun(1);
m.c2.fun(2);
}
}
结果:
Creating new Mugs in main
Cup(1)
Cup(2)
c1 & c2 initialized
Mugs()
fun(1)
fun(2)