履行一个公开的承诺,作一件有价值的事,一直坚持,就会有人看到,加油!html
下面哪一个不对?
正确答案: C 你的答案: 空 (错误)java
RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.oracle
method is not required to declare in its throws clause any subclasses of RuntimeExeption that might be thrown during the execution of the method but not caughtapp
An RuntimeException is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.函数
NullPointerException is one kind of RuntimeExceptionui
运行时异常: 都是RuntimeException类及其子类异常,如NullPointerException(空指针异常)、IndexOutOfBoundsException(下标越界异常)等,这些异常是不检查异常,程序中能够选择捕获处理,也能够不处理。这些异常通常是由程序逻辑错误引发的,程序应该从逻辑角度尽量避免这类异常的发生。 运行时异常的特色是Java编译器不会检查它,也就是说,当程序中可能出现这类异常,即便没有用try-catch语句捕获它,也没有用throws子句声明抛出它,也会编译经过。 非运行时异常 (编译异常): 是RuntimeException之外的异常,类型上都属于Exception类及其子类。从程序语法角度讲是必须进行处理的异常,若是不处理,程序就不能编译经过。如IOException、SQLException等以及用户自定义的Exception异常,通常状况下不自定义检查异常。
下面的对象建立方法中哪些会调用构造方法 ()?
正确答案: A C 你的答案: A (错误)spa
new语句建立对象指针
调用Java.io.ObjectInputStream的readObject方法code
java反射机制使用java.lang.Class或java.lang.reflect.Constructor的newInstance()方法orm
调用对象的clone()方法
题目的四个选项是构造方法new,序列化对象,反射,克隆分别建立一个对象的方法,,只有new和反射用到了构造方法
下列对继承的说法,正确的是( )
正确答案: A 你的答案: B (错误)
子类能继承父类的全部成员
子类继承父类的非私有方法和状态
子类只能继承父类的public方法和状态
子类只能继承父类的方法
使用反射能够看出子类是继承了父类的私有方法的(无论是不是final),只是直接调用父类的私有方法是不能够的,可是利用反射的方式能够调用。字段同理。 package work.litao; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Method; class Parent{ Parent() { System.out.println("调用父类构造方法!"); } private static void staticParent() { System.out.println("调用父类静态方法"); } private final void finalParent() { System.out.println("调用父类final方法"); } private void printParent(){ System.out.println("调用父类私有方法"); } } class Child extends Parent { public void printChild(){ System.out.println("调用子类公有方法"); } } public class Test { public static void main(String[] args) throws Exception { //获取子类 Class clazz = Class.forName("work.litao.Child"); //获得父类 Class superClass = clazz.getSuperclass(); //获得父类非继承的因此方法 Method[] methods = superClass.getDeclaredMethods(); //设置私有方法能够被访问 AccessibleObject.setAccessible(methods,true); for (Method m:methods) { System.out.println(); System.out.println("子类调用方法"+m.getName()+"()的调用结果:" ); m.invoke(new Child()); } } }
运行结果:
subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass. [子类从其父类继承全部成员(字段,方法和嵌套类)。 构造函数不是成员,因此它们不被子类继承,可是能够从子类调用超类的构造函数。]
来自Oracle官方文档https://docs.oracle.com/javas...