JavaÄÚ²¿ÀࣨInner Class£©
¼òµ¥µÄ˵£¬ÄÚ²¿£¨inner£©ÀàÖ¸ÄÇЩÀඨÒå´úÂë±»ÖÃÓÚÆäËüÀඨÒåÖеÄÀࣻ¶ø¶ÔÓÚÒ»°ãµÄ¡¢ÀඨÒå´úÂ벻ǶÌ×ÔÚÆäËüÀඨÒåÖеÄÀ࣬³ÆÎª¶¥²ã£¨top-level£©Àà¡£¶ÔÓÚÒ»¸öÄÚ²¿À࣬°üº¬Æä¶¨Òå´úÂëµÄÀà³ÆÎªËüµÄÍⲿ£¨outer£©Àà¡£
1 Static member class£¨¾²Ì¬³ÉÔ±Àࣩ
ÀàÉùÃ÷Öаüº¬“static”¹Ø¼ü×ÖµÄÄÚ²¿Àà¡£ÈçÒÔÏÂʾÀý´úÂ룬
Inner1/Inner2/Inner3/Inner4¾ÍÊÇOuterµÄËĸö¾²Ì¬³ÉÔ±Àà¡£¾²Ì¬³ÉÔ±ÀàµÄʹÓ÷½Ê½ÓëÒ»°ã¶¥²ãÀàµÄʹÓ÷½Ê½»ù±¾Ïàͬ¡£
public class Outer{
//just like static method, static member class has public/private/default access privilege levels
//access privilege level: public
public static class Inner1 {
public Inner1() {
//Static member inner class can access static method of outer class
staticMethod();
//Compile error: static member inner class can not access instance method of outer class
//instanceMethod();
}
}
//access privilege level: default
static class Inner2 {
}
//access privilege level: private
private static class Inner3 {
//define a nested inner class in another inner class
public static class Inner4 {
}
}
private static void staticMethod() {
//cannot define an inner class in a method
/*public static class Inner4() {
}*/
}
private void instanceMethod() {
//private static member class can be accessed only in its outer class definition scope
Inner3 inner3 = new Inner3();
//how to use nested inner class
Inner3.Inner4 inner4 = new Inner3.Inner4();
}
}
class Test {
Outer.Inner1 inner1 = new Outer.Inner1();
//Test and Outer are in the same package, so Inner2 can be accessed here
Outer.Inner2 inner2 = new Outer.Inner2();
//Compile error: Inner3 cannot be accessed here
//Outer.Inner3 inner3 = new Outer.Inner3();
}
1.1 ¾²Ì¬³ÉÔ±ÀàÌØÐÔ
¾²Ì¬³ÉÔ±Àà¿É·ÃÎÊÍⲿÀàµÄÈÎ
Ïà¹ØÎĵµ£º
/*
*ÈÕÆÚ:2010-04-18 20:02
*¿ª·¢Õß:heroyan
*ÁªÏµ·½Ê½:zndxysf@126.com
*¹¦ÄÜ:ÎÞÏòͼ×îСÉú³ÉÊ÷KruskalË㷨ʵÏÖ°¸Àý
*/
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
public class Kruskal{
private static int MAX = 100;
private ArrayList<Edge> edge = new Ar ......
ÔÚstylesheet±êÇ©ÀïÉùÃ÷ÃüÃû¿Õ¼äºÍµ÷Ó÷½·¨£º
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:proc="${path}/packageName" exclude-result-prefixes="proc">
......
<xsl:value-of select="proc:className.methodName(param)"/>
${path}Ëæ±ãÔõÑùд¶¼¿ÉÒÔ£¬¼´Ê¹ÊǸ ......
Javaͨ¹ýjava.lang.ThreadÀàÍê³É¶àÏ̡߳£ÎÒÃÇͨ¹ýͬһ¸öÀý×Ó£¬¿´Ï̵߳ÄÁ½ÖÖ´´½¨·½·¨£¬ÒÔ¼°ÔËÐз½·¨£º
(1)Ò»ÖÖÊÇÉùÃ÷ Thread µÄ×ÓÀà£¬ÖØÔØ Thread ÀàµÄ·½·¨ run£¨Extend java.lang.Thread and override the run method£©
public class MyThread extends Thread
{
&nb ......
½ñÌìÔÚ±àдһ¸ö¿ìËÙÅÅÐòº¯Êý£¬ÆäÖÐÏëÓÃÒ»¸öÔÚC++ÖÐÀàËÆswap¹¦Äܵĺ¯Êý£¬½á¹ûÒý·¢ÁËһϵÁеÄÎÊÌâ¡£
ÏÂÃæÊÇÔÚÍøÉÏËѵ½µÄ´úÂ룬²¢ÔÚÎҵı¾µØ»úÉÏ×÷ÁËÔËÐС£
public class ParamTest
{
public static void ......