}
public void aMethod(){
System.out.println("in First class");
}
}
public class Second extends First{
public void aMethod(){
System.out.println("in Second class");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Second();
}
}答:运行结果为in Second class
3、写出以下程序的运行结果
[java] public class T {
static boolean foo(char c){
System.out.print(c);
return true;
}
public static void main(String[] args) {
int i = 0;
for(foo('a');foo('b')&&(i<2);foo('c')){
i++;
foo('d');
}
}
}
public class T {
static boolean foo(char c){
System.out.print(c);
return true;
}
public static void main(String[] args) {
int i = 0;
for(foo('a');foo('b')&&(i<2);foo('c')){
i++;
foo('d');
}
}
}答:运行结果为:abdcbdcb。不知道为什么...
4、写出以下程序的运行结果
[java] class A{
static{
System.out.println("a static");
}
public A(){
System.out.println("a construct");
}
}
class B extends A{
static{
System.out.println("b static");
}
public B(){
System.out.println("b construct");
}
}
public class T {
public static void main(String[] args) {
// TODO Auto-generated method stub
A ab = new B();
ab = new B();
}
}
class A{
static{
System.out.println("a static");
}
public A(){
System.out.println("a construct");
}
}
class B extends A{
static{
System.out.println("b static");
}
public B(){
System.out.println("b construct");
}
}
public class T {
public static void main(String[] args) {
// TODO Auto-generated method stub
A ab = new B();
ab = new B();
}
}答:运行结果为
a static
b static
a construct
b construct
a construct
b construct