public class OuterClass
{
private static int i = 1;
private int j = 2;
private int k = 3;
private int p = 9;
public OuterClass()
{
//InterClass ic = new InterClass();
System.out.println(" ");
}
public static void out_f1()
{
//
System.out.println(" ");
}
public void out_f2()
{
//
System.out.println(" ");
}
/**
*
*/
public void out_f3()
{
Inner_Member im = new Inner_Member();
im.inner_f1();
}
/**
* ,
* 1:
* 2:
* 3:
*/
public static void out_f4()
{
OuterClass oc = new OuterClass();//
Inner_Member im = oc.new Inner_Member();//
im.inner_f1();
}
public static void main(String[] args)
{
OuterClass oc = new OuterClass();//
out_f4();
System.out.println("------------------- -------------------------------");
oc.out_f5(10);
System.out.println("------------------- -------------------------------");
oc.out_f6();
System.out.println("-------------------- ------------------------------");
System.out.println("--------------------- -----------------------------");
}
/**1.
* , 、 。
*
* : , 。
*
* :
* ⑴ , 。( PRIVATE, 。)
* ⑵ 。 private 。
*/
private class Inner_Member
{
int t = 12;
int j = 11;
//static int p = 5;//
public Inner_Member ()
{
System.out.println(" ");
}
void inner_f1()
{
System.out.println(" "+k);// ,
System.out.println(" "+OuterClass.this.i);
System.out.println(" "+i);
System.out.println(" "+OuterClass.this.j);// ' .this. '
System.out.println(" "+j);//
System.out.println(" "+this.j);// ‘this. ’
System.out.println(" "+t);
out_f1();
out_f2();
}
}
/**2.
* , , public private,
* :①
* ② ( ), final
*
*/
public void out_f5(int k)
{
final int s = 100;
int f_i = 300;
final int j = 200;
class Inner_part
{
int s = 21;
int p = 29;
//static int m = 20;//
Inner_part(int k)
{
inner_f(k);
}
int inner_i = 22;
void inner_f(int k)
{
System.out.println(" :"+i);// ,
System.out.println(" :"+s);// ( ), final
//System.out.println(" :"+f_i);
System.out.println(" :"+p);// ,
System.out.println(" :"+this.p);// "this. "
System.out.println(" :"+OuterClass.this.p);// " .this. "
// OuterClass oc = new OuterClass();
// System.out.println(" :"+oc.p);// ,
System.out.println(" :"+k);
}
}
new Inner_part(k);
}
/**3.
* , , static
* public,protected,private
* :
*/
private static class Inner_Static
{
static int k = 31;
int j = 32;
public Inner_Static()
{
System.out.println(" ");
}
static void inner_f1()
{
System.out.println(" :"+i);//
// System.out.println(" :"+k);
// System.out.println(" :"+);
// System.out.println(" :"+k);
out_f1();//
// out_f2();// ,
OuterClass oc = new OuterClass();
oc.out_f2();
}
void inner_f2()
{
//
}
}
/**
* , ,
*/
public void out_f6()
{
System.out.println(" "+Inner_Static.k);// : .
Inner_Static.inner_f1();
//
Inner_Static is = new Inner_Static();// :
System.out.println(is.j);
is.inner_f2();
}
/**
*
* ,
*
* :
* 1, , , 。
* 2, , 。
* 3, , 。
*
* : new , , , ,
* 。 , 。
* 。 。 Out$1.class。
* , 。 ,
* 。 , 。
* 。 , 。
*/
//
/*
*
* void init(){
p.add(yellow);
p.add(blue);
p.add(red);
f.add(p);
f.setSize(400, 300);
f.setTitle("ActionDemo");
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
f.setVisible(false);
f.dispose();
System.exit(0);
}
});
yellow.addActionListener(new ButtonAction(Color.yellow));
blue.addActionListener(new ButtonAction(Color.BLUE));
red.addActionListener(new ButtonAction(Color.RED));
}
*/
}