摘要: 13_内部类 太难了。 阅读全文
posted @ 2024-07-02 22:02 神莹 阅读(7) 评论(0) 推荐(0)
摘要: 12_接口 只有规范,自己无法写方法(专业的约束) 定义一些方法,让不同的人实现 方法默认public abstract 常量默认public static final 接口不能实例化,没有构造方法 可以实现多个接口,实现接口必须重写里面的方法 //接口都需要有实现类 public interfac 阅读全文
posted @ 2024-07-02 22:01 神莹 阅读(12) 评论(0) 推荐(0)
摘要: 11_抽象类 抽象类 public abstract class Action { //抽象方法,只有方法名字,没有方法实现 public abstract void dosomething(); } //继承抽象类必须实现抽象方法,除非它也是抽象类 public class A extends A 阅读全文
posted @ 2024-07-02 22:01 神莹 阅读(14) 评论(0) 推荐(0)
摘要: 10_static详解 public class Person { { System.out.println("匿名代码块"); } static{ System.out.println("静态代码块"); } public Person(){ System.out.println("构造方法"); 阅读全文
posted @ 2024-07-02 22:01 神莹 阅读(8) 评论(0) 推荐(0)
摘要: 09_instanceof关键字和类型转换 instanceof用于判断对象和类的关系是否为父子 //Object>String //Object>Person>Teacher //Object>Person>Student Object object = new Student();//引用obj 阅读全文
posted @ 2024-07-02 22:01 神莹 阅读(13) 评论(0) 推荐(0)
摘要: 08_多态 public class Application { public static void main(String[] args) { Student s1 = new Student(); Person s2 = new Student(); Object s3 = new Stude 阅读全文
posted @ 2024-07-02 22:00 神莹 阅读(11) 评论(0) 推荐(0)
摘要: 07_方法的重写 子类重写父类的方法 静态方法等级较高,不算重写 public class Application { public static void main(String[] args) { A a = new A(); a.test();//Atest //父类B的引用指向子类A B b 阅读全文
posted @ 2024-07-02 22:00 神莹 阅读(18) 评论(0) 推荐(0)
摘要: 06_super super super必须只能出现在子类的方法或子类的构造方法中! super调用父类构造方法,必须在构造方法的第一个 super和this不能同时调用构造方法! public class Application { public static void main(String[] 阅读全文
posted @ 2024-07-02 21:59 神莹 阅读(30) 评论(0) 推荐(0)
摘要: 05_继承 extends public class Person { private int money = 10_0000_0000; } public class Student extends Person{ } public class Teacher extends Person{ } 阅读全文
posted @ 2024-07-02 21:59 神莹 阅读(13) 评论(0) 推荐(0)
摘要: 04_封装 程序追求高内聚,低耦合 属性私有,get/set public class Student { private String name; private int age; private char gender; public String getName() { return this 阅读全文
posted @ 2024-07-02 21:59 神莹 阅读(17) 评论(0) 推荐(0)