Reply to this topicStart new topicStart Poll

> ¦³ÃöjavaªºStatic nested classes
¦Ô¤à¤ó
µoªí©ó¡G Jul 3 2010, 15:18 ¡@
Quote Post


¤Ï¼é¬y¤~¬O¤ý¹D¡I¡I
************

µoªí¼Æ¡G 6,255
©ÒÄݸs²Õ¡G ¤Ó¦u
µù¥U¤é´Á¡G 7-15-2007

¬¡ÅD¡G21
Án±æ¡G1540


§Ú¬Ý¹LJava tutorials¡A¦³Ãöstatic nested class¬O³o¼Ë¼gªº:

QUOTE
Static Nested Classes

As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class ¡X it can use them only through an object reference.
Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.


·Ó§Úªº²z¸Ñ¡AStatic Nested Classes¦n¹³¤@¯ëªºtop-level classªº¸Ü¡AÀ³¸Ó¬O¤£¯à°÷¦s¨úsuperclassùØ­±ªºprivate field¹À¡A¦ý¬O¤U­±ªº¥N½X¹B¦æ®É¨S¦³°ÝÃD...

CODE

public class Player implements Comparable, Cloneable {
...
   private int hp, atk, def, spd, mor;
...
   private static class RandomEvent {
...
       public RandomEventResult execute(Player p1, Player p2, int n){
...
       Player affectedPlayer = n == 1 ? p1 : p2;
...
           int tp = affectedPlayer.hp;
           affectedPlayer.hp = (int) (affectedPlayer.hp * (1 + actualAffectRate) + actualAffectValue);
//static nested classª½±µ¦s¨úsuperclassªºprivate field hp


³o¸Ì§Úı±o¦³ÂI§xÂZ¡A©Ò¥H·Q°Ý¨s³º§Ú¤W­±ªº¼gªk¦³¨S¤°»ò¦M¾÷¡AÁÙ¦³¦³Ãöstatic nested classªº¸Ô²Ó

¥»½g¤å³¹¤w³Q ¦Ô¤à¤ó ©ó Jul 3 2010, 15:22 ½s¿è¹L
PM
Top
°Ñ¿ÑABC
µoªí©ó¡G Jul 3 2010, 17:01 ¡@µû»ù¡G+1
Quote Post


¯«Áô¤§¥D¥Ç-¥Ã»·»P¶·ªØ¤§¸o¤H
************

µoªí¼Æ¡G 3,458
©ÒÄݸs²Õ¡G ¤Ó¦u
µù¥U¤é´Á¡G 9-18-2003

¬¡ÅD¡G15
Án±æ¡G1860


outer class=/=super class
PM
Top
°ªªø®¥
µoªí©ó¡G Jul 4 2010, 06:49 ¡@µû»ù¡G+1
Quote Post


¡ã('¡¾'*)
*********

µoªí¼Æ¡G 1,054
©ÒÄݸs²Õ¡G ¤Ó¦u
µù¥U¤é´Á¡G 9-18-2003

¬¡ÅD¡G9
Án±æ¡G435


Nested Class ´N¬O¯à°÷ª½±µ¦s¨ú Enclosing Class (Outer Class) ªº¥ô¦ómembers¡A¥]¬Aprivate members¡C
QUOTE
As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class ¡X it can use them only through an object reference.
¬O«üNested Static Class¥u¥i¥H³z¹Lobject reference¦s¨úEnclosing Classªºmembers¡C


--------------------
user posted image
PMEmail PosterUsers WebsiteIntegrity Messenger IM
Top
1 ¦ì¨Ï¥ÎªÌ¥¿¦b¾\Ū¥»¥DÃD (1 ¦ì³X«È¤Î 0 ¦ì°Î¦W¨Ï¥ÎªÌ)
0 ¦ì·|­û¡G

Topic Options Reply to this topicStart new topicStart Poll

 



[ Script Execution time: 0.0115 ]   [ 12 queries used ]   [ GZIP ±Ò¥Î ]