Compilation succeeds and 4 is printed.
Compilation succeeds and 43 is printed.
An error on line 9 causes compilation to fail.
An error on line 14 causes compilation to fail.
Compilation succeeds but an exception is thrown at line 9.
第1题:
此题为判断题(对,错)。
第2题:
class A { public String toString () { return “4”; } } class B extends A { 8. public String toString () { return super.toString() + “3”; } } public class Test { public static void main(Stringargs) { System.out.printIn(new B()); } } What is the result?()
第3题:
下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new Te
A.0
B.1
C.2
D.3
第4题:
class Super { public int getLenght() { return 4; } } public class Sub extends Super { public long getLenght() { return 5; } public static void main(String[] args) {Super sooper = new Super(); Sub sub = new Sub(); System.out.println( sooper.getLenght() + “,” + sub.getLenght() ); } } What is the output? ()
第5题:
Public class test ( Public static void main (String args[]) ( System.out.printIn (6 ^ 3); ) ) What is the output?()
第6题:
class Super { public Integer getLenght() { return new Integer(4); } } public class Sub extends Super { public Long GetLenght() { return new Long(5); } public static void main(String[] args) { Super sooper = new Super(); Sub sub = new Sub(); System.out.println( sooper.getLenght().toString() + “,” + sub.getLenght().toString() ); } } What is the output?()
第7题:
class Super { public int getLenght( ) { return 4; } } public class Sub extends Super { public long getLenght( ) { return 5; } public static void main(String[] args) { Super sooper = new Super( ); Sub sub = new Sub( ); System.out.println( sooper.getLenght( ) + “,” + sub.getLenght( ) ); } } What is the output?()
第8题:
阅读以下函数说明和Java代码,将应填入(n)处的字句写在对应栏内。
【说明】
下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的toString方法调用Point类中的toStrinS方法输出中心点的值。在MovingBsll类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值。
【Java代码】
//Point.java文件
public class Point{
private double xCoordinate;
private double yCoordinate;
public Point(){}
public Point(double x,double y){
xCoordinate=x;
yCoordinate=y;
}
public String toStrthg(){
return"("+Double.toString(xCoordinate)+","
+Double.toString(yCoordinate)+")";
}
//other methods
}
//Ball.java文件
public class Ball{
private (1);//中心点
private double radius;//半径
private String color;//颜色
public Ball(){}
public Ball(double xValue, double yValue, double r){
//具有中心点及其半径的构造方法
center=(2);//调用类Point中的构造方法
radius=r;
}
public Ball(double xValue, double yValue, double r, String c){
//具有中心点、半径和颜色的构造方法
(3);//调用3个参数的构造方法
color=c;
}
public String toString(){
return "A ball with center"+center.toString()
+",radius "+Double.toString(radius)+",color"+color;
}
//other methods
}
class MovingBall (4) {
private double speed;
public MovingBall(){}
public MoyingBall(double xValue, double yValue, double r, String c, double s){
(5);//调用父类Ball中具有4个参数的构造方法
speed=s;
}
public String toString(){
return super.toString()+",speed"+Double.toString(speed);
}
//other methods
}
public class test{
public static void main(String args[]){
MovingBall mb=new MovingBall(10,20,40,"green",25);
System.out.println(mb);
}
}
第9题:
class super { public int getLength() {return 4;} } public class Sub extends Super { public long getLength() {return 5;} public static void main (String[]args) { super sooper = new Super (); Sub sub = new Sub(); System.out.printIn( sooper.getLength()+ “,” + sub.getLength() }; } What is the output?()
第10题:
Public class test ( Public static void stringReplace (String text) ( Text = text.replace („j„ , „i„); ) public static void bufferReplace (StringBuffer text) ( text = text.append (“C”) ) public static void main (String args ){ String textString = new String (“java”); StringBuffer text BufferString = new StringBuffer (“java”); stringReplace (textString); BufferReplace (textBuffer); System.out.printIn (textString + textBuffer); } ) What is the output?()