访问修饰符(access modifier)
1) public(公共的):被public所修饰的属性和方法可以被所有类访问。
2) protected(受保护的):被protected所修饰的属性和方法可以在类内部、相同包以及该类的子类所访问。
3) private(私有的):被private所修饰的属性和方法只能在该类内部使用
4) 默认的(不加任何访问修饰符):在类内部以及相同包下面的类所使用。
instanceof运算符
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html 写道
The instanceof
operator compares an object to a
specified type. You can use it to test if an object is an instance of a
class, an instance of a subclass, or an instance of a class that
implements a particular interface.
The following program,
InstanceofDemo
, defines a parent class (named Parent
), a simple interface (named MyInterface
), and a child class (named Child
) that inherits from the parent and implements the interface.
class InstanceofDemo {
public static void main(String[] args) {
Parent obj1 = new Parent();
Parent obj2 = new Child();
System.out.println("obj1 instanceof Parent: "
+ (obj1 instanceof Parent));
System.out.println("obj1 instanceof Child: "
+ (obj1 instanceof Child));
System.out.println("obj1 instanceof MyInterface: "
+ (obj1 instanceof MyInterface));
System.out.println("obj2 instanceof Parent: "
+ (obj2 instanceof Parent));
System.out.println("obj2 instanceof Child: "
+ (obj2 instanceof Child));
System.out.println("obj2 instanceof MyInterface: "
+ (obj2 instanceof MyInterface));
}
}
class Parent {}
class Child extends Parent implements MyInterface {}
interface MyInterface {}
Output:
obj1 instanceof Parent: true
obj1 instanceof Child: false
obj1 instanceof MyInterface: false
obj2 instanceof Parent: true
obj2 instanceof Child: true
obj2 instanceof MyInterface: true
When using the instanceof
operator, keep in mind that null
is not an instance of anything.
分享到:
相关推荐
官方版本,亲测可用
官方版本,亲测可用
Access modifier 访问控制修饰符:访问控制修饰符用来修饰Java中类、以及类的方法和变量的访问控制属性。 Anonymous class 匿名类:当你需要创建和使用一个类,而又不需要给出它的名字或者再次使用的使用,就...
关键字public被称作访问修饰符(access modifier),用于控制程序的其它部分对这段代码的访问级别。 关键字class 表明Java 程序中的全部内容都包含在类中,Java是一种纯面向对象的语言。 一个源文件中至多...
The Quad Chamfer modifier produces all quad chamfers, unlike the normal 3ds Max chamfer which produces a lot of triangles and ngons. It is the successor of the Quad Chamfer maxscript, improving on by...
10. Which is a Java access modifier used to designate that a particular data field will not be inherited by a subclass? (a) final (b) protected (c) private (d) default 1. Consider the following ...
【IT十八掌徐培成】Java基础第25天-02.declaredMethod-method-Modifier.zip
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
名称:Ajax Modifier -------------------- 版本:1.5.3 作者:ygyooo 分类:其他 -------------------- 概述:此扩展仅覆盖 XMLHTTPRequest 对象中的响应数据以及 fetch 方法。 描述: .建议在不使用时关闭此扩展...
它是用于增加/减少所选 Java 文件 (.jar) 的 Java 堆大小的工具。 对于某些 Java 应用程序,默认的 Java 堆大小是不够的; 使用此工具,您可以轻松地临时增加一个文件的堆大小。 仅适用于 Windows。
官方版本,亲测可用
官方版本,亲测可用
File Modifier是一个多功能的EXE文件编辑器。 File Modifier功能:随意提取exe文件图标(与原始图标一致) 克隆任意exe文件图标 克隆任意exe文件版本信息 为exe文件添加区段、设置区段大小 为exe文件修改特征 ...
统信UOS资源包
用于Eclipse的AccessModifer插件允许用户更改工作台视图中Java类,接口,方法和字段的可见性(公共,受保护,默认,私有)和其他修饰符(最终,静态,同步)。
统信UOS资源包
这便是onnx-modifier (github)开发的动机。所有的编辑信息将最终汇总,统一送由ONNX Python API处理,得到编辑后的ONNX模型文件。 目前已支持下列操作: 1、删除/恢复节点 2、增加新节点 3、修改节点输入输出名 4、...
统信UOS资源包