1. 程式人生 > 其它 >基本語法-流程控制-分支結構

基本語法-流程控制-分支結構

package com.oop;

import com.oop.demo04.Person;
import com.oop.demo04.Student;
import com.oop.demo04.Teacher;

/**
 * <p>
 *
 * </p>
 *
 * @author: wfs
 * @date: 2021/6/21
 */
public class Application {
    public static void main(String[] args) {
        //Object > String
        //Object >Person>Teacher
        
//Object > Person>Student Object object = new Student(); //System.out.println("X instanceof Y");編譯能不能過,取決於存不存在父子關係 //結果取決於X所指向的實際型別是否為Y的子型別 System.out.println(object instanceof Student);//true System.out.println(object instanceof Person);//true System.out.println(object instanceof
Object);//true System.out.println(object instanceof Teacher);//false System.out.println(object instanceof String);//false System.out.println("====================="); Student student = new Student(); System.out.println(student instanceof Student);//true System.out.println(student instanceof
Person);//true System.out.println(student instanceof Object);//true //System.out.println(student instanceof Teacher);//編譯錯誤 // System.out.println(student instanceof String);//編譯錯誤 System.out.println("====================="); Person person = new Student(); System.out.println(person instanceof Student);//true System.out.println(person instanceof Person);//true System.out.println(person instanceof Object);//true System.out.println(person instanceof Teacher);//false // System.out.println(person instanceof String);//編譯錯誤 System.out.println("====================="); } }