2018年3月8日

摘要: * * * * * * * * * * * * * * * 阅读全文
posted @ 2018-03-08 20:40 三盛乙烯 阅读(108) 评论(0) 推荐(0) 编辑
摘要: * * * * * * * * * * * * * * * 阅读全文
posted @ 2018-03-08 20:37 三盛乙烯 阅读(125) 评论(0) 推荐(0) 编辑
摘要: package prepare1; import java.util.Arrays; public class Test { public static void main(String[] args) { int data[] = new int[] {1,5,6,3,8,9,2,4,7,10}; 阅读全文
posted @ 2018-03-08 20:05 三盛乙烯 阅读(94) 评论(0) 推荐(0) 编辑
摘要: toString()方法原本用来输出对象的完整信息 即对象的编码.如果不重写,输出的就是对象编码. 因为万类都是Object的子类,所以可以在任何类中重写toString()方法,这个方法可以自定义.只要返回值是String就行,因为API中对此有要求. 以下是API中对这一方法的描述: toStr 阅读全文
posted @ 2018-03-08 18:39 三盛乙烯 阅读(102) 评论(0) 推荐(0) 编辑
摘要: package prepare1; class Book{ } public class Test { public static void main(String[] args) { Object obj = new Object(); Object obj1 = new Book();//向上转型 Object obj2 = "字符串";//向上转型 Book ... 阅读全文
posted @ 2018-03-08 18:24 三盛乙烯 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 假设现在存在一个父接口A和一个子接口B. 父接口A中有一个方法,子接口B中既有父接口的方法,又有自己的方法. 因此,如果实例化的是父接口,则只能调用父接口中的那个方法. 如果实例化的是子接口,则既能用父接口的方法,又能用子接口的方法. 需要注意的是:如果接口被多继承, 那么这个接口中的某个方法,其方 阅读全文
posted @ 2018-03-08 16:49 三盛乙烯 阅读(121) 评论(0) 推荐(0) 编辑
摘要: package prepare1; interface A{ public void fun1(); } interface B1 extends A{ public void func2(); @Override default void fun1() { System.out.println("父接口的方法1"); ... 阅读全文
posted @ 2018-03-08 16:07 三盛乙烯 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 以Collection接口为例: Collection接口有两个子接口——List接口和Set接口. 其中,ArrayList是List接口的子类. 因此,既可以用ArrayList为上一层的List接口实例化, 也可以为上上层的Collection接口实例化. 子接口肯定比父接口的方法多(因为子接 阅读全文
posted @ 2018-03-08 15:39 三盛乙烯 阅读(1464) 评论(0) 推荐(0) 编辑
摘要: 所谓泛型,主要是应用在泛型类. 即类一开始定义的时候就采取泛型,使得类中的变量暂时不确定是什么类型. 最后,在泛型类实例化的时候,再确定该类中的变量是什么类型的. 结果: 100常规类的字符串字符串1字符串21020 阅读全文
posted @ 2018-03-08 14:52 三盛乙烯 阅读(138) 评论(0) 推荐(0) 编辑
摘要: package prepare1; class A {//类中的接口可以是public,也可以没有修饰符 interface B { } public interface C { } } interface D {//类以外的接口必须没有修饰符 } public class Test1 { public static void main(St... 阅读全文
posted @ 2018-03-08 14:00 三盛乙烯 阅读(153) 评论(0) 推荐(0) 编辑
摘要: public class Test1 implements TestInter{ public static void main(String[] args) { //TestInter ts = new Test1();//通过接口实例化 Test1 ts = new Test1();//通过类实例化 ts.func1();//二者效果相同,因为new的都是Test1() ... 阅读全文
posted @ 2018-03-08 13:53 三盛乙烯 阅读(335) 评论(0) 推荐(0) 编辑

导航