一.内部类学习导图 1>.静态内部类: 使用static修饰符来修饰内部类,则这个内部类就属于外部类本身,而不属于外部类的某个对象.因此使用static修饰的内部类被称为静态内部类. public class StaticInclass { private static int num; private int num1; private static int num2; /* * 创建一个静态内部类 * 静态内部类可以包含静态成员,也可以包含非静态成员. * 根据静态成员不能访问非静态成员的规
1995.5 Oak ——>java1.0 提出 write once run anywhere 1996.1 jdk1.0 jvm Sun Classic VM 1997.2 JDK1.1 内部类,反射,jar文件格式,jdbc,javabeans,rmi 1998 JDK1.2 j2EE, j2SE,j2ME,swing,jit,Hotspot VM 2000 JDK1.3 Timer,java2d 2002 JDK1.4 struts,hibernate,spring 1.x,正则表达式
class Test{ public void main(String[] args){ A testA=new A(); //这里会出现问题 new Thread(new Runnable(){ public void run(){ testA.printout(); } }).start(); System.out.println("aaaaaa"); } class A{ public void printout(){ System.out.println("aaaaa
内部类访问外部类的变量必须是final吗? 如下: package com.java.concurrent; class A { int i = 3; public void shout() { class B { public void shout1() { System.out.println(i); } } B b = new B(); b.shout1(); } public static void main(String[] args) { A a = new A(); a.shout
原因如下: 1.内部类可以访问外部类的成员变量 2.对象创建完成后对象的成员变量才会被分配空间 3.main的静态方法执行时可以不存在外部类,不创建实体对象 4.内部类能访问成员变量意味着一定存在外部类实体对象 因为3和4矛盾,所以在静态方法中不能new内部类的实体对象 这个是错误的 class demo{ public void func(){ //位置1: } class Inner{} public static void main(S
看到jdk某些接口中存在default方法,于是... http://shaomeng95.iteye.com/blog/998820 为什么接口只能是公有常量? public interface Jdk8新特性 { public static final String AA = "hhe"; default void test(){ System.out.println("哈哈"); } public static void hehe(){ System.o
1,内部类概述 定义:把A类定义在B类内部,则A类是内部类.如下所示: class Outer1{外部类 String name1; public void show(){ System.out.println("Outer1.show()"+new Inner1().name); } class Inner1{//内部类 String name; public void fun(){ System.out.println("Outer1.Inner1.fun()"
内部类 在Java中,可以将一个类定义在另一个类里面或者一个方法里面,这样的类称为内部类.广泛意义上的内部类一般来说包括这四种:成员内部类.局部内部类.匿名内部类和静态内部类.下面就先来了解一下这四种内部类的用法. 成员内部类 成员内部类可以无条件访问外部类的所有成员属性和成员方法(包括private成员和静态成员). class Circle { private double radius = 0; public static int count =1; public Circle(doubl
援引 Typesafe Enums - This flexible object-oriented enumerated type facility allows you to create enumerated types with arbitrary methods and fields. It provides all the benefits of the Typesafe Enum pattern ("Effective Java," Item 21) without the