• java 面向对象


    1.this :

    2.构造器:

     3.static:

    1. package jiHeStudy;
    2. public class Test03 {
    3. public static void main(String[] args) {
    4. //类变量只有一个
    5. Student stu = new Student();
    6. //对象.出类变量可赋值,不推荐
    7. stu.userName = "wwx";
    8. System.out.println(stu.userName);
    9. Student stu1 = new Student();
    10. //第二次对象.点出类变量赋值,会覆盖之前的赋值
    11. stu1.userName = "lr";
    12. System.out.println(stu.userName);
    13. }
    14. }

     

    4.类方法设计工具类(静态方法):

     5.类方法,实例方法的注意事项:

    6.代码块:

    7.单例类:

    8.权限修饰符: 

    9.继承注意事项 

    10重写 :

    11.子类访问其他成员变量:

    12.子类构造器的特点:

    13.子类构造器应用:

    1. package jiHeStudy;
    2. public class Test03 {
    3. public static void main(String[] args) {
    4. Teacher t = new Teacher("lishi",11,"java");
    5. System.out.println(t);
    6. }
    7. }
    8. class Teacher extends People {
    9. String skill;
    10. public Teacher(String name,int age,String skill) {
    11. super(name,age);
    12. this.skill = skill;
    13. }
    14. @Override
    15. public String toString() {
    16. return "Teacher{" +
    17. "skill='" + skill + '\'' +
    18. ", name='" + name + '\'' +
    19. ", age=" + age +
    20. '}';
    21. }
    22. }
    23. class People {
    24. String name;
    25. int age;
    26. public People() {
    27. }
    28. public People(String name, int age) {
    29. this.name = name;
    30. this.age = age;
    31. }
    32. }

     13.this(参数)调用兄弟构造器:

      

    14.什么是多态:

    1. package duotai;
    2. public class Test {
    3. public static void main(String[] args) {
    4. People p1= new Teacher();
    5. p1.run();
    6. System.out.println(p1.name);
    7. People p2= new Student();
    8. p2.run();
    9. System.out.println(p2.name);
    10. }
    11. }
    12. package duotai;
    13. public class People {
    14. String name="父类";
    15. void run(){
    16. System.out.println("跑步");
    17. }
    18. }
    19. package duotai;
    20. public class Teacher extends People{
    21. String name="t";
    22. @Override
    23. void run() {
    24. System.out.println("老师跑");
    25. }
    26. }
    27. package duotai;
    28. public class Student extends People{
    29. String name="s";
    30. @Override
    31. void run() {
    32. System.out.println("学生跑");
    33. }
    34. }

     

    15.多态好处:

    16.final:

    17.常量:

    18.抽象类: 

     

    19.模板方法:

     

    1. package duotai;
    2. public class Test {
    3. public static void main(String[] args) {
    4. People p1 = new Teacher();
    5. p1.sing();
    6. System.out.println("-----------------------");
    7. People p2 = new Student();
    8. p2.sing();
    9. }
    10. }
    11. package duotai;
    12. public abstract class People {
    13. //模板方法
    14. public final void sing(){
    15. System.out.println("开始唱歌");
    16. dosing();
    17. System.out.println("结束唱歌");
    18. }
    19. abstract void dosing();
    20. }
    21. package duotai;
    22. public class Teacher extends People{
    23. //重写抽象方法
    24. @Override
    25. void dosing() {
    26. System.out.println("老师们合唱");
    27. }
    28. }
    29. package duotai;
    30. public class Student extends People{
    31. //重写抽象方法
    32. @Override
    33. void dosing() {
    34. System.out.println("学生们合唱");
    35. }
    36. }

     

     20.接口:

    21.内部类:

     21.1 4种形式:

    21.2创建格式: 

    21.3成员内部类访问其他成员的特点: 

     

    21.4总结:

    21.5静态内部类:

     ​​

    21.6局部内部类: 

    21.7匿名内部类!!!:

    1. package jiHeStudy;
    2. import java.util.ArrayList;
    3. import java.util.Scanner;
    4. public class Tset02 {
    5. /*
    6. 动态开辟集合
    7. */
    8. public static void main(String[] args) {
    9. // Animal a= new Cat();
    10. // Cat a = new Cat();
    11. // a.cry();
    12. Animal a = new Animal() {
    13. @Override
    14. public void cry() {
    15. System.out.println("喵喵喵");
    16. }
    17. };
    18. a.cry();
    19. }
    20. }
    21. //class Cat extends Animal{
    22. // @Override
    23. // public void cry() {
    24. // System.out.println("喵喵喵");
    25. // }
    26. //}
    27. abstract class Animal{
    28. public abstract void cry();
    29. }

    1. package Inner;
    2. public class Test {
    3. public static void main(String[] args) {
    4. /*
    5. new Swimming() {
    6. @Override
    7. public void swim() {
    8. System.out.println("猫游泳");
    9. }
    10. }
    11. 这一串相当于一个猫的实例对象,可直接做方法的参数
    12. */
    13. goGame(new Swimming() {
    14. @Override
    15. public void swim() {
    16. System.out.println("猫游泳");
    17. }
    18. });
    19. }
    20. public static void goGame(Swimming s){
    21. System.out.println("开始比赛");
    22. s.swim();
    23. }
    24. }
    25. interface Swimming {
    26. void swim();
    27. }

     21泛型:

    22泛型类

    22.泛型接口:

    23.泛型方法:

    24.泛型擦除:

  • 相关阅读:
    Spring核心问题回顾1:ioc容器创建的大致过程、bean的生命周期、解决循环依赖为什么需要三级缓存
    药物从研发到上市需要经历哪些流程?||新药研发
    JAVA毕业设计WEB儿童运动馆业务信息系统计算机源码+lw文档+系统+调试部署+数据库
    【Linux】Rocky 9.0 Podman服务无法正常启动
    进亦忧,退亦忧,Github Copilot 集成进入 Visual Studio 带来的思考
    谷粒商城-day13-es和商品上架
    JsonUtility和LitJson的特点与区别
    Triangle Attack: A Query-efficient Decision-based Adversarial Attack
    基于Java的智能仓库(进销存)管理系统设计与实现(源码+lw+部署文档+讲解等)
    如何优化百度搜索引擎?(10个技巧让你的网站更容易被搜索到)
  • 原文地址:https://blog.csdn.net/qq_64005599/article/details/133868883