java instanceof 关键字
来源:互联网 发布:我们如何看待网络用语 编辑:程序博客网 时间:2024/06/07 02:47
java 中使用instanceof 关键字判断一个对象到底是否是不是一个类的实例(判断返回值 是 布尔类型值)
案例代码 如下:
package csdn.zyl.demo;
class A12{
public void tell1()
{
System.out.println("A12--tell1");
}
public void tell2()
{
System.out.println("A12--tell2");
}
}
class B1 extends A12{
public void tell1(){
System.out.println("B1--tell1");
}
public void tell3(){
System.out.println("B1--tell3");
}
}
public class DuoTaiDemo {
class A12{
public void tell1()
{
System.out.println("A12--tell1");
}
public void tell2()
{
System.out.println("A12--tell2");
}
}
class B1 extends A12{
public void tell1(){
System.out.println("B1--tell1");
}
public void tell3(){
System.out.println("B1--tell3");
}
}
public class DuoTaiDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
//向上转型
// System.out.println("向上转型结果");
// B1 b = new B1();
// A12 a = b;
// a.tell1(); //tell1 ()重写
// a.tell2();
// //向下 转型
// System.out.println("向下转型结果");
A12 a1 = new B1();
B1 b1 = (B1)a1;
System.out.println(a1 instanceof B1);
System.out.println(b1 instanceof A12);
}
// TODO Auto-generated method stub
//向上转型
// System.out.println("向上转型结果");
// B1 b = new B1();
// A12 a = b;
// a.tell1(); //tell1 ()重写
// a.tell2();
// //向下 转型
// System.out.println("向下转型结果");
A12 a1 = new B1();
B1 b1 = (B1)a1;
System.out.println(a1 instanceof B1);
System.out.println(b1 instanceof A12);
}
}
案例 结果
true
true
true
阅读全文
0 0
- [Java] instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- java中的instanceof 关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java中的instanceof关键字
- Java 中 instanceof关键字
- Java Web实现使用浏览器从服务器下载文件(后台)
- 检测文件被占用
- mackeeper病毒解决方法
- spring+freemarker+springMvc+mybatis+maven整合
- 【待总结】const * int,const int *,const &问题
- java instanceof 关键字
- bzoj1081: [SCOI2005]超级格雷码
- JQuery判断复选框是否选中
- 系统例外
- git图形化统计工具
- 简单实用的双向电平转换电路(非常实用!)
- ubuntu没网环境安装libreoffice和unoconv,用以word转pdf用
- 【Linux\云服务器】CentOS 7.2 64位 可视化桌面的安装与卸载
- Kotlin入门教程系列(一)Kotlin HelloWorld