1、分布式架构第十八单元试题及答案分布式架构第十八单元试题及答案您的姓名: 填空题 *_下面代码Java变量定义正确的是35. String #name=Jane Doe36. int %age = 24;37. Double _height = 123.5;38. double temp = 37.5; 单选题第35行第36行第37行(正确答案)第38行public class TestString public static void main(String args) String str = 420; str += 42; System.out.println(str); 输出结果是: 单
2、选题4242046242042(正确答案)public class Test public static void main(String args) int x = 5; boolean b1 = true; boolean b2 = false; if(x=4) & !b2) System.out.println(1 ); System.out.println(2 ); if(b2=true) & b1) System.out.println(3 ); 输出结果是: 单选题231 22 3(正确答案)public void go() String o = ; z: for(int x=0;
3、i3;x+) for(int y=0;y2;y+) if(x = 1) break; if(x=2 & y=1) break z; o = o + x + y; System.out.println(o);输出结果是: 单选题000001000120(正确答案)00012021int x = 0;int y = 10;do y-; +x;while(x5);System.out.println(x+,+y);输出结果是: 单选题5,65,5(正确答案)6,56,6public class Breaker static String o = ; public static void main(S
4、tring args) z: o = o + 2; for(int x=3;x8;x+) if(x = 4) break; if(x = 6) break z; o = o + x; System.out.println(o); 输出结果是: 单选题23234234567编译错误(正确答案)public class Breaker2 static String o = ; public static void main(String args) z: for(int x=2;xdistance)(story*2)=tail) System.out.println(1); if(distance
5、+1 != tail)(story*2)=distance) System.out.println(2); 输出结果是: 单选题1212无输出(正确答案)String elements = for,tea,too;String first = (elements.length0)?elements0:null;输出结果是: 单选题编译错误运行时抛出异常first赋值为nullfirst赋值为elements0(正确答案)import java.util.*;public class Quest public static void main(String args) String colors
6、=blue,red,green,yellow,orange; Arrays.sort(colors); int s2 = Arrays.binarySearch(colors,orange); int s3 = Arrays.binarySearch(colors,violet); System.out.println(s2+ +s3); 输出结果是: 单选题2-12-42-5(正确答案)编译错误class Alligator public static void main(String args) int x = 1,2,3,4,5,6,7,8,9; int y = x; System.ou
7、t.println(y21); 输出结果是: 单选题237(正确答案)编译错误public class Barn public static void main(String args) new Barn().go(hi,1); new Barn().go(hi,world,2); public void go(String. y,int x) System.out.println(yy.length-1+ ); 输出结果是: 单选题hi hihi worldworld world编译错误(正确答案)class Person String name = No name; public Pers
8、on(String nm)name = nm;class Employee extends Person String empId = 0000; public Employee(String id)empId = id;class EmployeeTest public static void main(String args) Employee e = new Employee(4321); System.out.println(e.empId); 输出结果是: 单选题43210000运行时抛出异常编译错误(正确答案)class Mud /将下面代码放到这里, System.out.pri
9、ntln(hi); 一共有多少选项可以正常编译public static void main(String.a)public static void main(String.* a)public static void main(String. a)public static void main(String. a)public static void main(String. a) 单选题0123(正确答案)class Atom Atom()System.out.print(atom );class Rock extends Atom Rock(String type)System.out.
10、print(type);public class Mountain extends Rock Mountain() super(granite ); new Rock(granite ); public static void main(String a)new Mountain();输出结果是: 单选题编译错误atom granitegranite granite(正确答案)atom granite atom granitepublic class Blip protected int blipvert(int x)return 0;class Vert extends Blip /下面代码
11、放在这里1. public int blipvert(int x)return 0;2. private int blipvert(int x)return 0;3. private int blipvert(long x)return 0;4. protected long blipvert(int x)return 0;5. protected int blipvert(long x)return 0;6. protected long blipvert(long x)return 0;7. protected long blipvert(int x,int y)return 0;一共有多
12、少选项放在上面可以正常编译 单选题0245(正确答案)1.class Super2.3. private int a;4. protected Super(int a)this.a = a;5.6.class Sub extends Super7.8. public Sub(int a)super(a);9. public Sub()this.a = 5;10.上面代码如下修改可以编译通过 单选题修改第2行为public int a;修改第2行为protected int a;修改第13行为public Sub()this(5);(正确答案)修改第13行为public Sub()super(a
13、);class Batman int squares = 81; public static void main(String args) new Batman().go(); void go() incr(+squares); System.out.println(squares); void incr(int squares)squares+=10;输出结果是: 单选题8182(正确答案)9192class Pass public static void main(String args) int x = 5; Pass p = new Pass(); p.doStuff(x); Syst
14、em.out.println( main x = +x); void doStuff(int x) System.out.println( doStuff x = +x+); 输出结果是: 单选题编译错误运行时抛出异常doStuff x=6 main x=6doStuff x=5 main x=5(正确答案)class ClassA public int numberOfInstances; protected ClassA(int numberOfInstances) this.numberOfInstances=numberOfInstances; class ExtendedA exte
15、nds ClassA private ExtendedA(int numberOfInstances) super(numberOfInstances); public static void main(String args) ExtendedA ext = new ExtendedA(420); System.out.println(ext.numberOfInstances); 输出结果是: 单选题420(正确答案)运行时抛出异常所有构造方法必须声明为public构造方法不能声明为私有class One void foo()class Two extends One /下面代码放在这里一
16、共有多少选项可以放在上面可以正常编译1.int foo()2.void foo()3.public void foo()4.private void foo()5.protected void foo() 单选题013(正确答案)2class X X()System.out.print(1); X(int x) this(); System.out.print(2); public class Y extends X Y() super(6); System.out.print(3); Y(int y) this(); System.out.println(4); public static
17、void main(String a)new Y(5);输出结果是: 单选题131341234(正确答案)2134public class Hi void m1() protected void m2()class Lois extends Hi /下面哪些代码可以放在这里输出结果是:public void m1()(正确答案)protected void m1()(正确答案)private void m1()void m2()class One public One foo()return this;class Two extends One public One foo()return t
18、his;class Three extends Two /下面哪些代码可以放在这里A.public void foo()B.public int foo()return 3;C.public Two foo()return this;D.public One foo()return this;public void foo()public int foo()return 3;public Two foo()return this;(正确答案)public One foo()return this;(正确答案)class Employee String name;double baseSalar
19、y; public Employee(String name,double baseSalary) this.name = name; this.baseSalary = baseSalary; public class SalesPerson extends Employee double commission; public SalesPerson(String name, double baseSalary,double commission) /下面哪些代码可以放在这里编译运行 super(name,baseSalary);(正确答案)mission = commission;supe
20、r();mission = commission;super(name,baseSalary);mission = commission;(正确答案)public abstract class Shape private int x; private int y; public abstract void draw(); public void setAnchor(int x,int y) this.x = x; this.y = y; 下面定义正确的是:public class Circle implements Shape private int radius;public abstrac
21、t class Circle extends Shape private int radius;(正确答案)public class Circle extends Shape private int radius; public void draw();public class Circle extends Shape private int radius; public void draw();(正确答案)class ClassAclass ClassB extends ClassAclass ClassC extends ClassAClassA p0 = new ClassA();Cla
22、ssB p1 = new ClassB();ClassC p2 = new ClassC();ClassA p3 = new ClassB();ClassA p4 = new ClassC();下面哪几个赋值语句是合法的p0=p1(正确答案)p1=p2p1 = (ClassB)p3(正确答案)p2 = (ClassC)p4(正确答案)class ThingyMeter m = new Meter();class Component void go()System.out.print(c);class meter extends Component void go()System.out.pri
23、nt(m);class DeluxeThingy extends Thingy public static void main(String args) DeluxeThingy dt = new DeluxeThingy(); dt.m.go(); Thingy t = new DeluxeThingy(); t.m.go(); 下面描述正确的是:输出mm(正确答案)输出mcDeluxeThingy has-a Component(正确答案)以上都不对abstract public class Employee protected abstract double getSaleAmount(
24、); public double getCommision() return getSalesAmount()*0.15; class Sales extends Employee /下面哪些代码放在这里可以正确运行double getSalesAmount()return 1230.45;public double getSalesAmount()return 1230.45;(正确答案)private double getSalesAmount()return 1230.45;protected double getSalesAmount()return 1230.45;(正确答案)pub
25、lic interface Status /*下面哪些修饰符可以放在这里*/ int MY_VALUE=10;final(正确答案)static(正确答案)nativepublic(正确答案)下面哪些类正确实现java.lang.Runnable和java.lang.Cloneable接口public class Session implements Runnable,Cloneable public void run(); public Object clone();public class Session extends Runnable,Cloneable public void run
26、(). public Object clone().public class Session implements Runnable,Cloneable public void run(). public Object clone().(正确答案)public abstract class Session implements Runnable,Cloneable public void run(). public Object clone().(正确答案)10.interface Foo11. int bar();12.13.14.public class Beta15.16. class
27、A implements Foo17. public int bar()return 1;18. 19.20. public int fubar(Foo foo)return foo.bar();21.22. public void testFoo()23.24. Class A implements Foo25. public int bar()return 2;26. 27.28. System.out.println(fubar(new A();29. 30.31. public static void main(String argv)32. new Beta().testFoo();
28、33. 34.下面哪些语句是正确的编译错误代码可以编译,运行输出2(正确答案)如果第16,17,18行删除,输出2(正确答案)如果第24,25,26行删除,输出1(正确答案)Java语言是编译类型语言 判断题对错(正确答案)同一个JVM中同一个的类可以被加载多次 判断题对(正确答案)错long类型8个字节,float类型4个字节,long类型中最大数比float类型中最大的数要更大 判断题对错(正确答案)Java语言无法调用C语言编写的DLL动态链接库 判断题对错(正确答案)在Java语言中字符A占一个字节,汉字中占两个字节 判断题对错(正确答案)在Java语言中int和char类型可以相互转换 判断题对(正确答案)错在Java语言中可以集成父类的方法和属性,我们可以写一个类继承java.lang.String 判断题对错(正确答案)Java语言中,有八种基本数据类型 判断题对(正确答案)错Java可以开发桌面程序,也可以开发服务器端程序 判断题对(正确答案)错Java类中启动方法可以是public static void main(String arg) 判断题对(正确答案)错
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2