韩世雷程序员 2019-06-21
成功自律一次(延迟满足)
package test_heima_08; public class Test_Demo04 { public static void main(String[] args){ Son s1 = new Son(); s1.test(); } } class Father{ private String name = "apple"; public String getName(){ return name; } } class Son extends Father{ public void test(){ System.out.println(this.getName());//直接调用继承自父类的getName() System.out.println(getName());//这样写等同于上面的写法 System.out.println(super.getName());//直接调用父类的getName() } }
package test_heima_08; public class Test_Demo05 { public static void main(String[] args){ final Demo05 a = new Demo05(10,"aaa"); //a = new Demo05(20,"bbb"); a.setAge(200); System.out.println(a.getAge()); final int b = 10; //b = 20; } } class Demo05{ private int age; private String name; public Demo05(int age,String name){ this.age = age; this.name = name; } public void setAge(int age){ this.age = age; } public int getAge(){ return age; } }
class Demo { final int num = 5; // final int num; //没有使用构造方法初始化,又这样不赋值,编译器会报错,final成员变量的默认初始值是无效值。 public void print(){ System.out.println(num); } }
class Demo { final int num; public Demo(){ num = 10; } public void print(){ System.out.println(num); } }
叨逼叨两句收拾收拾~18-11:Collection中的常见方法sortpackage com.test.demo001;System.out.println; //根据默认排序结果获取集合中的最大值