Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Inner classes in Java, the mystery within.

Inner classes, also called Nested Classes, are nothing but classes that are defined within other classes. The nesting is a relationship between classes, not objects.
Inner classes have clearly two benefits, name control & access control. In Java, this benefit is not as important because Java packages give the name control.
Java inner classes have feature that makes them richer and more useful. An object of an inner class has an implicit reference to the outer class object that instantiated it. Through this pointer, it gains access to any variable of the outer object. Only static inner classes don’t have this pointer. It is actually invisible when we write the code, but compiler takes care of it. Inner classes are actually a phenomenon of the compiler and not the JVM.
Inner classes may be defined with following access modifiers : public, protected, private, or with default package access.
The syntax for inner class is as follows:
[modifiers] class OuterClassName {
code...
[modifiers] class InnerClassName {
code....
}
}
Inner Classes:
Following properties can be noted about Inner classes:
The outer class (the class containing the inner class) can instantiate as many number of inner class objects as it wishes, inside it’s code.
If the inner class is public & the containing class as well, then code in some other unrelated class can as well create an instance of the inner class.
In above case the inner class can be created as follows:
<OuterClassName> outerObj = new <OuterClassName>(arguments);
outerObj.<InnerClassName> innerObj = outerObj.new <InnerClassName>(arguments);
No inner class objects are automatically instantiated with an outer class object.
If the inner class is static, then static inner class can be instantiated without an outer class instance, otherwise, the inner class object must be associated with an instance of the outer class.
Inner class code has free access to


Ïà¹ØÎĵµ£º

java Éú³ÉxmlÎļþ

import java.awt.Image;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
public class createXml
{
public static boolean writeXml(String path,String dir,String wpath,String wname)
{
File[] files = ReaderListFiles(path);
boo ......

javaÓÅÐãÊé¼®


      
 
1£©Java Language Specification, Third Edition (by James Gosling) 
 
     ±¾ÊéÓÉJava¼¼ÊõµÄ·¢Ã÷Õß±àд£¬ÊÇJava TM±à³ÌÓïÑÔµÄȨÍþÐÔ¼¼ÊõÖ¸ÄÏ¡£Èç¹ûÄãÏëÖªµÀÓïÑÔÖ®¹¹ÔìµÄ¾«È·º¬Ò壬±¾ÊéÊÇ×îºÃµÄ×ÊÔ´¡£      
&nbs ......

Java³ÌÐòµ÷Óô洢¹ý³ÌÓ¦ÓþÙÀý

Java³ÌÐòµ÷Óô洢¹ý³ÌÑéÖ¤Óû§µÇ¼
package com.yzy.jdbc.dao;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import oracle.jdbc.OracleTypes;
public class LoginDao {
 public boolean loginValidate(String username, Stri ......

javaÐéÄâ»ú

ʲôÊÇJavaÐéÄâ»ú
JavaÐéÄâ»ú£¨Java Virtual Machine) ¼ò³ÆJVM
¡¡¡¡JavaÐéÄâ»úÊÇÒ»¸öÏëÏóÖеĻúÆ÷,ÔÚʵ¼ÊµÄ¼ÆËã»úÉÏͨ¹ýÈí¼þÄ£ÄâÀ´ÊµÏÖ¡£JavaÐéÄâ»úÓÐ×Ô¼ºÏëÏóÖеÄÓ²¼þ,Èç´¦ÀíÆ÷¡¢¶ÑÕ»¡¢¼Ä´æÆ÷µÈ,»¹¾ßÓÐÏàÓ¦µÄÖ¸Áîϵͳ¡£
JavaÐéÄâ»úµÄÌØµã
¡¡¡¡JavaÓïÑÔµÄÒ»¸ö·Ç³£ÖØÒªµÄÌØµã¾ÍÊÇÓëÆ½Ì¨µÄÎÞ¹ØÐÔ¡£¶øÊ¹ÓÃJavaÐéÄâ»úÊÇÊµÏ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ