首页 > 其他分享 >instance------判断一个对象是什么类型,两个之间是否有父子关系

instance------判断一个对象是什么类型,两个之间是否有父子关系

时间:2022-08-29 10:26:02浏览次数:47  
标签:instanceof System 父子关系 instance Student ------ println true out

public class Person {
}

public class Student extends Person{
}

public class Teacher extends Person {
}


public class Amplication {

    public static void main(String[] args) {
        Object object = new Student();

        //instance  判断 = 号两边是否有父子关系
        System.out.println(object instanceof Student); // true   object是Student类的一个实例化
        System.out.println(object instanceof Person);  //true
        System.out.println(object instanceof Object);  // true
        System.out.println(object instanceof Teacher); //false
        System.out.println("================================");

        //new一个Student类的实例,但是属于Person类
        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("=================================");

        //new一个Student类的实例化,但属于Teacher类
        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); //false
    }
    }

 

标签:instanceof,System,父子关系,instance,Student,------,println,true,out
From: https://www.cnblogs.com/Hangli123/p/16634967.html

相关文章

  • 漫谈测试成长之探索——测试用例评审
    在分享测试用例评审的内容之前,我们可以先思考下为什么要组织测试用例评审会议呢?一、评审目的一般来说,参加测试用例评审的人员包括对应项目的产品人员、设计人员、开发人......
  • 上周热点回顾(8.22-8.28)
    热点随笔:· 拒绝加班:巧用前端电子表格中构建公式树 (葡萄城技术团队)· 被一个问题卡了近两天,下班后我哭了...... (久曲健)· 一个奇葩的线上问题,导致我排查了一天......
  • 塘下摩托车驾校流程记录
      一、报名我是21年8月15拿的c1驾照,22年8月28到塘下摩托车考场去报名,一开始百度导航错了,导航到汀田车管所对面了,打电话问才知道,那里只是一个报名处,周末不开门的,后......
  • 图数据库入门教程(一)简单理解图数据库
    以下内容是个人的理解,一家之言,可能误导,但能入门为什么会有图数据库?作为研发,我们接触最多的当属关系型数据库:Mysql、Oracle,还有一些非关系型数据库:MongoDB、Redis等,再广......
  • 电商项目项目讲解【杭州多测师】【杭州多测师_王sir】
    我们最近的项目做的是一个电商的项目,主要包含了首页、购物车、订单管理、个人中心等模块,我们客户可以通过我们的首页进行商品的选购并提交订单,此时我们系统会调用创建订单......
  • realpath函数,返回规范化的绝对路径名
    PHP中的realpath()函数是一个内置函数,用于返回规范化的绝对​​路径名。小编主要用于linux与window下路径问题的处理.之前小编本地的w11,程序运行的好好的.上传到服务器上......
  • Lombok首字母小写,第二个字母大写的问题
    一、问题描述最近在和前端对接接口的时候,发现后端接口返回给前端的一个字段大小写有问题,具体如下。使用的开发框架及版本:框架:SpringMVC;Lombok版本:1.18.12;对象简化后......
  • php大文件分片上传插件
    ​需求:项目要支持大文件上传功能,经过讨论,初步将文件上传大小控制在500M内,因此自己需要在项目中进行文件上传部分的调整和配置,自己将大小都以501M来进行限制。 第一步:......
  • 盛最多水的容器
    目录题目描述解题思路解题代码题目描述题目地址:https://leetcode.cn/problems/container-with-most-water/题目要求给定一个长度为n的整数数组 height 。有 n......
  • 二级目录进行伪静态配置
    本文主要为了记录使用pb的过程中遇到的伪静态配置问题.使用背景:在phpstudy中设置好了伪静态规则,但是因为一些其他原因需要添加新的伪静态规则.(phpstudy中设置的伪静态......