首页 > 其他分享 >2023.7.26 周三:instanceof

2023.7.26 周三:instanceof

时间:2023-07-26 19:57:36浏览次数:38  
标签:instanceof 26 System 2023.7 Student println True out

 1 /*
 2 instancof 判断两个类之间是否有继承关系
 3 Object->String
 4 Object->Person->Teacher
 5 Object->Person->Student
 6 */
 7 Object s1 = new Student();
 8 System.out.println(s1 instanceof Object);//True
 9 System.out.println(s1 instanceof Person);//True
10 System.out.println(s1 instanceof Student);//True
11 System.out.println(s1 instanceof Teacher);//False
12 System.out.println(s1 instanceof String);//False 
13 Person s2 = new Student();
14 System.out.println(s2 instanceof Object);//True
15 System.out.println(s2 instanceof Person);//True
16 System.out.println(s2 instanceof Student);//True
17 System.out.println(s2 instanceof Teacher);//False
18 //System.out.println(s2 instanceof String);//编译错误
19 Student s3 = new Student();
20 System.out.println(s3 instanceof Object);//True
21 System.out.println(s3 instanceof Person);//True
22 System.out.println(s3 instanceof Student);//True
23 //System.out.println(s2 instanceof Teacher);//编译错误
24 //System.out.println(s2 instanceof String);//编译错误
25     
26 public static void main(String[] args){
27     Student s = new Student();
28     s.student();
29     Person p = s;//子转父
30     
31     Person obj = new Student();
32     ((Student)obj).student();//父转子
33 }    

 

标签:instanceof,26,System,2023.7,Student,println,True,out
From: https://www.cnblogs.com/muzhaodi/p/17583407.html

相关文章

  • 2023年7月26日 天气:晴
        今天早上起来背了10个英语单词,然后学习了一个小时的java,写了一会英语阅读,然后和朋友出去打了两个小时的羽毛球,最后写了一会作业。    明天打算看一小时的电视剧,然后和朋友出去玩一会,打一两个小时的篮球,最后晚上练一小时的字,然后学习一小时的java。......
  • 7.26日
    一辆车,相约几位朋友,背上几个行囊,趁着青春正好,乘风而来,踏云而去。即刻出发吧,逃离城市的喧嚣,去远方,看见多种生活方式,在闹市里奔忙,在熙攘里踌躇,闻闻草原的芳香,遥望天边的星河。在岁月的时光中,行旅在不曾失语的人间烟火,遥岑于石刻寥若的千年印记。即刻出发吧,到很远的地方去吹风,寻觅......
  • 7.26
    Java数据结构Java工具包提供了强大的数据结构。在Java中的数据结构主要包括以下几种接口和类:枚举(Enumeration)位集合(BitSet)向量(Vector)栈(Stack)字典(Dictionary)哈希表(Hashtable)属性(Properties)枚举(Enumeration)接口虽然它本身不属于数据结构,但它在其他数据结构的范畴里应用......
  • 7.26 后记
    T1不用估价,被骗了正常bfs即可T2会爆__int128,不用记\(a+kb\)的和,一点一点减T3T4匈牙利邻接矩阵\({C_{i,j}}^k\)为\(i\rightarrowj\)恰好经过\(k\)条边的最短路\[C_{i,j}=\sum_{l_1,l_2\dotsl_k}a_{i,l_1}a_{i,l_2}a_{l_{k-1},j}\]园方数P5025CF555E......
  • 行业追踪,2023-07-26,如果主力不骗人,化工原料和磷化工有第一波机会
    自动复盘2023-07-26凡所有相,皆是虚妄。若见诸相非相,即见如来。k线图是最好的老师,每天持续发布板块的rps排名,追踪板块,板块来开仓,板块去清仓,丢弃自以为是的想法,板块去留让市场来告诉你跟踪板块总结:成交额超过100亿排名靠前,macd柱由绿转红成交量要大于均线有必要给每个行......
  • 暑假集训D3 2023.7.26 补题
    G.P6183[USACO10MAR]TheRockGameS题意:给定长度n,构造\(2^n\)个由X和O组成的字符串,使得第一个字符串和最后一个字符串只由O组成,并且相邻的字符串只有一处不同,不得有重复的字符串.BFS貌似做不了.看题解有佬用格雷码的知识.代码如下#include<stdio.h>#include<st......
  • 7/26
    问题B:最优乘车#include<bits/stdc++.h>usingnamespacestd;intm,n,vis[501];vector<int>g[501];intst;voidbfs(){queue<int>q;while(!q.empty())q.pop();q.push(1);vis[1]=0;while(!q.empty()){inth=q.front()......
  • 20230726
    复赛完全背包定义:有n种物品和一个容量为v的背包,第i种物品体积为c[i],价值为w[i],每种物品有无穷件,问如何选取物品放入背包,可使价值总和最大。与01背包的区别:01背包一个物品只能选一件,而完全背包一个物品可以选多件例题时间:1s空间:128M题目描述:一个旅行者有一个最......
  • 2023-7-26 Dynamic替代部分反射的简单实现方式
    Dynamic与反射的使用【作者】长生实体类publicclassSchool{ publicintGetAge(){ return100;}}使用反射获取对象里的方法 Schoolschool=newSchool(); varmethod=typeof(School).GetMethod("GetAge"); intage=(int)method.Invoke(school,null); Console.W......
  • Day16(2023.07.26)
    行程9:00 到达上海市徐汇区宛平南路1099号城建大厦9:45  与客户进行漏扫方面交流11:30--13:00   吃饭休息13:30         管理方面交流16:30         下班......