public class DD {
public static void main(String[] args) {
new Carrier(2);
}
}
class Carrier{
public static C c1 = new C(1);
public C c2 = new C(3);
public Carrier(int number) {
new C(number);
}
}
class C{
public C(int number){
System.out.println(number);
}
输出
1
3
2
public class FinallyAndReturn {
public static void main(String[] args) {
System.out.println(getVal());
}
public static int getVal() {
int i = 0;
try {
return i;
} finally {
i = 1;
}
}
}
输出0
public class SuperC {
public SuperC() {
printOut();
}
public void printOut() {
System.out.println("Super print out");
}
public static void main(String[] args) {
new SubC();
}
}
class SubC extends SuperC{
public SubC() {
printOut();
}
public void printOut() {
System.out.println("Sub print out");
}
}
输出
Sub print out
Sub print out
public class SuperC {
public SuperC() {
printOut();
}
private void printOut() {
System.out.println("Super print out");
}
public static void main(String[] args) {
new SubC();
}
}
class SubC extends SuperC{
public SubC() {
printOut();
}
public void printOut() {
System.out.println("Sub print out");
}
}
输出
Super print out
Sub print out