---------------------------------------------------
public static void main(String[] args) {
try {
System.out.println(1);
problem();
} catch (RuntimeException e) {
System.out.println(2);
}catch (Exception e) {
System.out.println(3);
}finally{
System.out.println(4);
}
System.out.println(5);
}
private static void problem() throws Exception {
throw new Exception();
}
----------------输出1345---------------------------------
方法重载(Overloading)和方法重写(Overriding)都是多态性的表现
(1)方法重载是一个类中定义了多个方法名相同,而他们的参数的数量不同或数量相同而类型和次序不同,则称为方法的重载(Overloading)
(2)方法重写是在子类存在方法与父类的方法的名字相同,而且参数的个数与类型一样,返回
值也一样的方法,就称为重写(Overriding)
(3)方法重载是一个类的多态性表现,而方法重写是子类与父类的一种多态性表现.
------------------------------------------------------------------------
public class test01 {
public static void main(String[] args) {
A anA = new B();
anA.print();
}
}
class B extends A {
public B() {
}
public void print() {
System.out.println('B');
}
}
class A {
private int a;
public A() {
}
public A(int a) {
this.a = a;
}
public void print() {
System.out.println('A');
}
}
-----------------------输出B-------------------
wait()、notify()、notifyAll()是三个定义在Object类里的方法,可以用来控制线程的状态。
-----------------------------------------------------
StringBuffer stringBuffer = new StringBuffer("12345678901234567890123456");
int c = stringBuffer.capacity();
System.out.println(stringBuffer.length());//26
System.out.println(c); //42
public StringBuffer(CharSequence seq) {
this(seq.length() + 16);
append(seq);
}
2)new StringBuffer();
答:16。
------------------------------------------------------