面向对象编程

时间:2020-04-04 23:44:26   收藏:0   阅读:76

面向对象编程

面向对象

构造器

封装

封装的步骤

继承

Java中类只允许单继承,没有多继承,一个儿子只能有一个爸爸,一个爸爸可以有多个儿子

super注意点:

this:

多态

Instanceof

package com.chen.demo01;
?
import com.chen.demo02.Person;
import com.chen.demo02.Student;
import com.chen.demo02.Teacher;
public class Application {
   public static void main(String[] args) {
       //关系object>string
       //关系Object>person>student
       //关系object>person>teacher
       Object object = new Student();
       System.out.println(object instanceof Object);//true
       System.out.println(object instanceof Person);//true
       System.out.println(object instanceof Student);//true
       System.out.println(object instanceof Teacher);//flase
       System.out.println(object instanceof String);//flase
       System.out.println("============================");
       Person person = new Student();
       System.out.println(person instanceof Object); //true
       System.out.println(person instanceof Person);//true
       System.out.println(person instanceof Student);//true
       System.out.println(person instanceof Teacher);//flase
       //System.out.println(person instanceof String);
       System.out.println("============================");
       Student student = new Student();
       System.out.println(student instanceof Object);//true
       System.out.println(student instanceof Person);//true
       System.out.println(student instanceof Student);//true
       //System.out.println(student instanceof Teacher);
       //System.out.println(student instanceof String);
  }
}

Static

package com.chen.demo03;
?
public class Person {
  {
       //匿名代码块
       System.out.println("匿名代码块");
  }
   static {
       //静态代码块
       System.out.println("static");
  }
   //运行顺序为static>匿名代码块>构造方法
   public void run(){
       System.out.println("构造方法");
  }
}

抽象类

原文:https://www.cnblogs.com/Kentstudy/p/12634267.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!