public class Demo05 { public static void main(String[] args) { Demo04 outer = new Demo04(18); Demo04.A b = outer.new A(); b.getAge();
// new Demo04(18);//匿名类
} }
public class Demo04 { private int m_age; Demo04(int a) { m_age = a; } public class A{ public void getAge() { System.out.println(m_age); } } }
静态内部类以及局部内部类
public class Demo06 { int age; static int b; public static class B{//静态内部类,无法访问非静态的属性 public void put(){ System.out.println(b); class C{//局部内部类,写在方法里面的,不建议使用
public class Demo11 { public static void main(String[] args) { Test test = new Test(); Thread thread = new Thread(test); Thread thread1 = new Thread(test); Thread thread2 = new Thread(test); thread2.setPriority(Thread.MIN_PRIORITY); thread2.start(); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); thread1.setPriority(Thread.MAX_PRIORITY); thread1.start(); } } class Test implements Runnable{
@Override public void run() { System.out.println(Thread.currentThread().getName()+"的优先级为"+Thread.currentThread().getPriority()); } }
public class DirList { public static void main(String args[]) { String dirname = "/java"; File f1 = new File(dirname); if (f1.isDirectory()) { System.out.println("Directory of " + dirname); String s[] = f1.list(); for (int i = 0; i < s.length; i++) { File f = new File(dirname + "/" + s[i]); if (f.isDirectory()) { System.out.println(s[i] + " is a directory"); } else { System.out.println(s[i] + " is a file"); } } } else { System.out.println(dirname + " is not a directory"); } } }
public class Demo05 { public static void main(String[] args) { Demo04 outer = new Demo04(18); Demo04.A b = outer.new A(); b.getAge();
// new Demo04(18);//匿名类
} }
public class Demo04 { private int m_age; Demo04(int a) { m_age = a; } public class A{ public void getAge() { System.out.println(m_age); } } }
静态内部类以及局部内部类
public class Demo06 { int age; static int b; public static class B{//静态内部类,无法访问非静态的属性 public void put(){ System.out.println(b); class C{//局部内部类,写在方法里面的,不建议使用
public class Demo11 { public static void main(String[] args) { Test test = new Test(); Thread thread = new Thread(test); Thread thread1 = new Thread(test); Thread thread2 = new Thread(test); thread2.setPriority(Thread.MIN_PRIORITY); thread2.start(); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); thread1.setPriority(Thread.MAX_PRIORITY); thread1.start(); } } class Test implements Runnable{
@Override public void run() { System.out.println(Thread.currentThread().getName()+"的优先级为"+Thread.currentThread().getPriority()); } }
public class DirList { public static void main(String args[]) { String dirname = "/java"; File f1 = new File(dirname); if (f1.isDirectory()) { System.out.println("Directory of " + dirname); String s[] = f1.list(); for (int i = 0; i < s.length; i++) { File f = new File(dirname + "/" + s[i]); if (f.isDirectory()) { System.out.println(s[i] + " is a directory"); } else { System.out.println(s[i] + " is a file"); } } } else { System.out.println(dirname + " is not a directory"); } } }