instanceof 的语法格式如下:

myobject instanceof ExampleClass

myobject:某类的对象引用

ExampleClass:某个类

 class Quadrangle{
public static void draw(Quadrangle q) {
}
} class Square extends Quadrangle { } class Anything { }
public class Parallelogram extends Quadrangle { public static void main(String[] args) { Quadrangle q = new Quadrangle();
//判断父类对象是否为Parallelogram子类的一个实例
if(q instanceof Parallelogram) {
Parallelogram p = (Parallelogram) q;
}
if(q instanceof Square){
Square s = (Square)q;
}
} }

instanceof操作符判断对象类型的更多相关文章

  1. 使用instanceof操作符判断对象类型及方法的重载

    学习内容: 一.使用instanceof操作符判断对象类型 1.instanceof操作符可以判断一个实例对象是否属于一个类. 语法:对象名 instanceof 类名 2.使用instanceof表 ...

  2. json转String 和 String转json 和判断对象类型

    function ajaxGetMenuList(){ $.getJSON("login.do", function(json){ var r = ""; zN ...

  3. JavaScript判断对象类型及节点类型、节点名称和节点值

    一.JavaScript判断对象类型 1.可以使用typeof函数判断对象类型 function checkObject1(){ var str="str"; console.lo ...

  4. c++派生类中构造函数和析构函数执行顺序、判断对象类型、抽象类、虚函数

    一. 代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include&l ...

  5. JavaScript中判断对象类型方法大全2

    在JavaScript中,有5种基本数据类型和1种复杂数据类型,基本数据类型有:Undefined, Null, Boolean, Number和String:复杂数据类型是Object,Object ...

  6. JavaScript中判断对象类型方法大全1

    我们知道,JavaScript中检测对象类型的运算符有:typeof.instanceof,还有对象的constructor属性: 1) typeof 运算符 typeof 是一元运算符,返回结果是一 ...

  7. JavaScript中判断对象类型的种种方法

    我们知道,JavaScript中检测对象类型的运算符有:typeof.instanceof,还有对象的constructor属性: 1) typeof 运算符 typeof 是一元运算符,返回结果是一 ...

  8. javascript 判断对象类型

    typeof typeof是一个一元运算符,它返回的结果 始终是一个字符串,对不同的操作数,它返回不同的结果. 此表总结了typeof所有可能的返回值: 操作数类型 返回值 undefined &qu ...

  9. 转 JavaScript中判断对象类型的种种方法

    我们知道,JavaScript中检测对象类型的运算符有:typeof.instanceof,还有对象的constructor属性: 1) typeof 运算符 typeof 是一元运算符,返回结果是一 ...

随机推荐

  1. 父Prefab与子prefab问题

    PrefabRevolution 原文:http://framebunker.com/blog/poor-mans-nested-prefabs/   (溜还是老外溜啊) 有些时候需要在Prefab里 ...

  2. Cracking the coding interview--Q1.6

    原文: Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a m ...

  3. 分布式文件系统 FastDFS Ceph

    分布式文件系统 FastDFS Cephhttp://www.oschina.net/p/fastdfshttp://www.oschina.net/p/ceph FastDFS 的 Go 客户端 f ...

  4. Linux sar使用

    [root@ywcrmdb ~]# sar -d 1 10 Linux 2.6.32-220.el6.x86_64 (ywcrmdb)  2014年04月19日  _x86_64_ (4 CPU) 1 ...

  5. COJ 0560 4015划分数

    4015 划分数 难度级别:B: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 有n个无区别的物品,将他们划分成不超过m组,求出划分方法数模 ...

  6. C#request 请求响应

    /// <summary> /// 提交POST请求 /// </summary> /// <param name="url">提交地址< ...

  7. httpclient post请求实例(自己写的)

    package com.gop.gplus.trade.common.utils; import org.apache.commons.httpclient.HttpClient;import org ...

  8. (转)在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送

    在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送 From: http://saeapns.sinaapp.com/doc.html 1,在 ...

  9. (转)三星i9500/Galaxy S4 刷基带教程

    一.手机基带是什么? 三星手机的基带用通俗的话来说就是手机中的一个负责信号调节并进行传输给系统的电路设置,基带的好坏直接影响到在同等信号强度下,手机的获取信号的能力. 二.为什么要刷基带? 常说的基带 ...

  10. 路径问题以及cookie详解

    1.路径问题: 注意 .代表执行程序的文件夹路径,在tomcat中也就是bin目录,所以要用this.getServletContext().getRealPath("/WEB-INF/cl ...