2013年9月9日

java匿名内部类

摘要: package frank;import java.lang.*;public class App{ public static void main(String[] args) { App a = new App(); a.println(new Product(){//匿名内部类。 public int get() { return 10; } public int out() { return 20; } }); } public void println(Product p) { System.out.println("get方法输出值:"+... 阅读全文

posted @ 2013-09-09 23:08 wp456 阅读(130) 评论(0) 推荐(0)

2013年9月4日

java内部类

摘要: package frank;import java.lang.*;public class App{ public static void main(String[] args) { Test1 t1 = new Test1(); Test1.Test2 t2; t2 = t1.new Test2(); t2.get(); Test1.Test3 t3 = new Test1.Test3(); }}class Test1{ private int age = 0; public Test1() { System.out.println("外部类"); } public cl 阅读全文

posted @ 2013-09-04 23:28 wp456 阅读(139) 评论(0) 推荐(0)

2013年8月29日

java非静态内部类

摘要: package frank;import java.lang.*;public class App{ public static void main(String[] args) { Integer i1 = 127; Integer i2 = 127; System.out.println(i1==i2); App a = new App(); a.get(); } private void get() { App02 a=new App02(); a.print(); } private int age; private class App02 { private int... 阅读全文

posted @ 2013-08-29 23:04 wp456 阅读(353) 评论(0) 推荐(0)

2013年8月7日

命令模式

摘要: package frank;public class App{ public static void main(String[] args) { int[] array = new int[]{0,1,4,5,3,4}; ProcessArray pa = new ProcessArray(); pa.process(array,new PrintCommand());//相同的方法,不同的输出 pa.process(array,new AddCommand());//相同的方法,不同的输出 }}interface Command{ public abstract void proce... 阅读全文

posted @ 2013-08-07 16:20 wp456 阅读(162) 评论(0) 推荐(0)

接口

摘要: package frank;public class App implements Person{ public static void main(String[] args) { App ct = new App(); System.out.println(Person.AGE); } public void get(){};//实现接口,不实现接口的话就只能定义成抽象类。}interface Person extends Person2{ public static final int MAX_SIZE = 10; int AGE = 20; public abstract void .. 阅读全文

posted @ 2013-08-07 10:47 wp456 阅读(212) 评论(0) 推荐(0)

java抽象类

摘要: 关键字:abstract。一个类中有抽象方法或者继承了抽象类或者接口,但是未实现方法,那么这个类必须是抽象类,且不能用final关键字修饰。字段、构造器、类方法不能定义为抽象的。抽象方法不能和private修饰符一起使用。抽象方法不能用static一起使用。局部变量不能定义为抽象的。 阅读全文

posted @ 2013-08-07 10:06 wp456 阅读(122) 评论(0) 推荐(0)

2013年8月6日

自定义缓存类

摘要: package frank;public class App{ public static void main(String[] args) { CacheTest ct1 = CacheTest.valueOf("1"); CacheTest ct2 = CacheTest.valueOf("1"); String s1 = new String("1"); String s2 = new String("1"); System.out.println(ct1 == ct2);//true System.out. 阅读全文

posted @ 2013-08-06 11:43 wp456 阅读(168) 评论(0) 推荐(0)

2013年8月5日

java中不可变类

摘要: package frank;/*真正的不可变类*/public class App{ private final Name name; public App(final Name name) { this.name = new Name(name.getFirstName(),name.getLastName()); } public Name getName() { return new Name(name.getFirstName(),name.getLastName()); } public static void main(String[] args) { Name name =... 阅读全文

posted @ 2013-08-05 22:05 wp456 阅读(172) 评论(0) 推荐(0)

java中final关键字

摘要: package frank;public class App{ public static void main(String[] args) { Person p = new Person(); final String s1 = "1";//使用final 把它变成宏变量,仅限直接量。 //s1 = "1"; 这样子赋值后就不会是宏变量 final String s2 = "2";//使用final 把它变成宏变量,仅限直接量。 String s3 = "12"; String s4 = s1 + s2;//执行 阅读全文

posted @ 2013-08-05 14:09 wp456 阅读(213) 评论(0) 推荐(0)

java单利模式

摘要: package frank;public class App{ public static void main(String[] args) { Person p1 = Person.getInstance(); p1.setAge(10); Person p2 = Person.getInstance(); System.out.println(p2.getAge()); }}class Person{ private int age; private Person() {} private static Person instances; public static Person ... 阅读全文

posted @ 2013-08-05 11:28 wp456 阅读(208) 评论(0) 推荐(0)

导航