1、难度级别:3知识点:继承(5-4)试题内容:class Art Art() System.out.println(“Art constructor“);class Drawing extends Art Drawing() super();System.out.println(“Drawing constructor“);public class Cartoon extends Drawing Cartoon() super();System.out.println(“Cartoon constructor“);public static void main(String args) Cart
2、oon x = new Cartoon();难度级别:3知识点:继承(5-4)试题内容:class Game Game(int i) System.out.println(“Game constructor“);class BoardGame extends Game BoardGame(int i) super(i);System.out.println(“BoardGame constructor“);public class Chess extends BoardGame Chess() super(11);System.out.println(“Chess constructor“);
3、public static void main(String args) Chess x = new Chess();难度级别:3知识点:继承(5-4)试题内容:class Vehicle public void drive() System.out.println(“Vehicle: drive“);class Car extends Vehicle public void drive() System.out.println(“Car: drive“);public class Test public static void main (String args ) Vehicle v= n
4、ew Vehicle();Car c= new Car();v.drive();c.drive();v = c;v.drive();难度级别:3知识点:构造函数的重载(5-3)试题内容:写出下面程序的输出结果class C0 public C0(int x) System.out.println(“C0“+x);C0() System.out.println(“C0“); class C1 extends C0public C1(int x) System.out.println(“C1“+x);public static void main (String args) new C1(1);
5、难度级别:3知识点:构造函数的重载(5-3)3、试题内容:写出下面程序的输出结果class Parent Parent() System.out.println(“调用父类的 parent()构造方法“);class SubParent extends Parent SubParent() System.out.println(“调用子类的 SubParent()构造方法“);public class Subroutine extends SubParent Subroutine() System.out.println(“调用子类的 Subroutine()构造方法“);public sta
6、tic void main(String args) Subroutine s = new Subroutine(); 难度级别:3知识点:构造函数的重载(5-3)试题内容:class Testpublic static int MAX=100;Test()System.out.println(“调用无参构造方法“);Test(int i)System.out.println(“调用有参构造方法“);public int f(int a)return a+Test.MAX;public int f(int a,int b)return a+b;public class TestDemopubl
7、ic static void main(String args)System.out.println(Test.MAX);Test t1=new Test();System.out.println(t1.f(10,20);Test t2=new Test(10);System.out.println(t2.f(10);难度级别:3知识点:构造函数(4-1)试题内容:查看下列程序并指出其输出结果。class Apublic A()System.out.println(“A is called“);class B extends Apublic B()super();System.out.prin
8、tln(“B is called“);public B(String x) super();System.out.println(“B is called and input is “+x);class C extends Bpublic C()System.out.println(“C is called“);public C(String x) super(x);System.out.println(“c is called and input String is “+x);public static void main(String args)new C(“how are you“);难
9、度级别:3知识点:构造函数(4-1)试题内容:以下程序的输出结果是 。public class Test extends TT public static void main ( String args ) Test t = new Test (“Tom“); public Test(String s ) super(s);System.out.println(“How do you do?“); public Test() this (“I am Jack“); class TT public TT() System.out.println(“What a pleasure!“); publ
10、ic TT(String s) this();System.out.println(“I am “+s); 难度级别:3知识点:重载试题内容:public class Exam3_3public static void main(String args) System.out.println( test(15,26,4) ); static int test(int x, int y, int z) return test( x, test(y,z);static int test(int x,int y) if(xy) return x;else return y;难度级别:3知识点:重载(
11、5-3)试题内容:以下程序段的输出结果为 。class IntORStringvoid iosM( int i )System.out.print(“Integer ”);void iosM(String s)System.out.print(“String ”);public static void main(String args )IntORString ios=new IntORString ( );ios.iosM(a);ios.iosM(“1”);难度级别:3知识点:重载(5-3)3、试题内容:以下程序段的输出结果为 public class OverLoadTest public
12、 static int add(int a, int b) return a + b; public static double add(double a, double b) return a + b;public static int add(int a) return a; public static int add(int a, double b) return 1; public static int add(double a, int b) return 1; public static void main(String args) System.out.println(“调用 a
13、dd(int,int)方法:“ + add(1, 2);System.out.println(“调用 add(double,double)方法:“ + add(2.1, 3.3);System.out.println(“调用 add(int)方法:“ + add(1);难度级别:3知识点:重载(5-3)试题内容:以下程序段的输出结果为 public class Yikes public static void go(long n)System.out.println(“long“);public static void go(short n)System.out.println(“short“
14、);public static void go(int n)System.out.println(“int“);public static void main(String args) short y=6;long z=7;go(y);go(z); 难度级别:3知识点:对象的比较试题内容:以下程序的输出结果是 。class Compare public static void main(String args)String str1 = new String(“abc“);String str2 = new String(“abc“);String str3 = str1;if(str1=st
15、r2)System.out.println(“str1=str2“);elseSystem.out.println(“str1!=str2“);if(str1=str3)System.out.println(“str1=str3“);elseSystem.out.println(“str1!=str3“);难度级别:3知识点:异常3、以下程序段的输出结果为 public class DemoFinally public static void main(String args)String members=new String4;for(int count=0;count3;count+) t
16、ry int x;if (count=0) x=1/0;if (count=1) members4=“jishou“;if (count=2) return; catch(ArrayIndexOutOfBoundsException e)System.out.println(“下标越界“);catch(ArithmeticException ex)System.out.println(“被零除“);continue; finally System.out.println(“这条语句总会被执行“); 二、按要求编写程序:1.(1)编写一个父类 Test,其中有两个构造方法(一个有参数,一个没有参
17、数)和一个方法 fun()。(2)编写一个子类 Test2继承 Test类,也有两个构造方法(一个有参数,一个没有参数) ,其中无参的构造方法调用父类对应的构造方法;重写方法 fun(),在该方法中要求用 super来调用父类的同名方法。(3)编写一个测试类 TestDemo,在 main方法中分别用父类和子类创建对象,并调用各自的方法 fun()。2.编写一个矩形类 Rect,包含:两个 protected属性:矩形的宽 width;矩形的高 height。两个构造器方法:(1)一个带有两个参数的构造器方法,用于将 width和 height属性初化;(2)一个不带参数的构造器,将矩形初始化为宽和高都为 10。两个方法:(1) 求矩形面积的方法 area()(2) 求矩形周长的方法 perimeter()