class Base{

    int
x = 1;

    static
int
y = 2;

    String name(){

        return
"mother";

    }

    static String staticname(){

        return
"static mother";

    }

}

class Subclass extends Base{

    int
x = 4;

    int
y = 5;

    int
z = 6;

    String name(){

        return
"baby";

    }

    static String staticname(){

        return
"static baby";

    }

}

public
class Test02{

    public
static
void main(String[] args){

        Subclass s = new Subclass();

        if(s instanceof Subclass){

            System.out.println(s.x+" "+s.y+" "+s.name()+" "+s.staticname());

 

        }

        

        Base s1 = s;

        if(s1 instanceof Subclass){

            System.out.println(s1.x+" "+s1.y+" "+s1.name()+" "+s1.staticname());

        

        }

        

        Base s2 = new Base();

        if(s2 instanceof Subclass){

            System.out.println(s2.x+" "+s2.y+" "+s2.name()+" "+s2.staticname());

        

        }

        

    }

}

/*

结果:

4 5 baby static baby

1 2 baby static mother

 

结论:

instanceof
用来判定对象A是否为类B的对象,或者A,B之间是否存在继承关系

如果A,B之间是不否存在继承关系,则编译不过

 

*/

最新文章

  1. TCP应用编程
  2. IOS 问题集锦
  3. 事件异步(EAP)使用事件异步处理一些耗时操作
  4. GUI开发者桌面搜索文件工具
  5. canvas API ,通俗的canvas基础知识(二)
  6. Bootstrap:弹出框和提示框效果以及代码展示
  7. git 基本命令
  8. 微服务架构下分布式Session管理
  9. webservice 发布到外网的时候
  10. javabeans的运用
  11. MySql数据库学习--存储过程(1)
  12. Office 2010 垃圾邮件过滤设置
  13. bzoj 5288: [Hnoi2018]游戏
  14. nodejs版本更新问题:express不是内部或外部命令
  15. 微信公众号通过图片选取接口上传到阿里oss
  16. QT5中无法包含Qtgui头文件的问题。
  17. 微信多客服插件获取openid
  18. mysql获取下一篇和上一篇文章的ID
  19. you
  20. mysql链接 显示 error: 'Access denied for user 'root'@'localhost' (using password: NO)'

热门文章

  1. Codeforces1111D Destroy the Colony 退背包+组合数
  2. Qt生成CSV 文件
  3. LeetCode.905-按奇偶排序数组(Sort Array By Parity)
  4. Shiro 权限管理框架
  5. java模拟进程调度之模拟抢占试多级轮转调度(附带可视化解决方案)
  6. html中id name class的区别(转)
  7. 使用CSS 实现菱形图片,斜条纹背景
  8. with rollup
  9. 面向对象多继承(C3算法)/网络编程
  10. 防止a标签跳转的几种方法