更多"现有: public class Pet( ) public clas"的相关试题:
[单项选择] public class TestSeven extends Thread { private static int x; public synchronized void doThings() { int current = x; current++; x = current; } public void run() { doThings(); } } Which is true?()
A. Compilation fails.
B. An exception is thrown at runtime.
C. Synchronizing the run() method would make the class thread-safe.
D. The data in variable “x” are protected from concurrent access problems.
E. Declaring the doThings() method as static would make the class thread-safe.
F. Wrapping the statements within doThings() in a synchronized(new Object()) {} block would make the class thread-safe.
[多项选择] public class Team extends java.util.LinkedList { public void addPlayer(Player p) { add(p); } public void compete(Team opponent) { /* more code here */ } } class Player { /* more code here */ } Which two are true?()
A. This code will compile.
B. This code demonstrates proper design of an is-a relationship.
C. This code demonstrates proper design of a has-a relationship.
D. A Java programmer using the Team class could remove Player objects from a Team object.
[单项选择] Public class Holt extends Thread{ Private String sThreadName; Public static void main(String argv[]) { Holt h=new Holt(); h.go(); Holt(){}; Holt(String s){ sThreadName=s; Public String getThreadName() { return sThreadName;} } Public void go(){ Hot first=new Hot("first"); first.start(); Hot second=new Hot("second"); second.start(); } Public void start() { For(int i=0;i<2;i++) { System.out.print(getThreadName()+i); Try{ Thread.sleep(100); }catch(Exception e){ System.out.print(e.getMessage()) ; } } } } 当编译运行上面代码时,将会出现()
A. 编译时错误
B. 输出first0,second0,first0,second1
C. 输出first0,first1,second10,second1
D. 运行时错误
[单项选择] public class Holt extends Thread{ private String sThreadName; public static void main(String argv[]){ Holt h = new Holt(); h.go(); } Holt(){} Holt(String s){ sThreadName = s; } public String getThreadName(){ return sThreadName; } public void go(){ Holt first = new Holt("first"); first.start(); Holt second = new Holt("second"); second.start(); } public void start(){ for(int i = 0; i < 2; i ++){ System.out.println(getThreadName() +i); try{ Thread.sleep(100); } catch(InterruptedException e){ System.out.println(e.getMessage()); } } } } 当编译运行上面的Java代码时,将会出现()。
A. 编译时错误
B. 输出first0, second0, first0, second1
C. 输出first0, first1, second0, second1
D. 运行时错误
[单项选择] public class Starter extends Thread { private int x= 2; public static void main(String[] args) throws Exception { new Starter().makeItSo(); } public Starter() { x=5; start(); } public void makeItSo() throws Exception { join(); x=x- 1; System.out.println(x); } public void run() { x *= 2; } } What is the output if the main() method is rum?()
A. 4
B. 5
C. 8
D. 9
E. Compilation fails.
F. An exception is thrown at runtime.
G. It is impossible to determine for certain.
[单项选择] public class A extends Thread { A() { setDaemon(true); } public void run() { (new B()).start(); try { Thread.sleep(60000); } catch (InterruptedException x) {} System.out.println(“A done”); } class B extends Thread { public void run() { try { Thread.sleep(60000); } catch (InterruptedException x) {} System.out.println(“B done”); } } public static void main(String[] args) { (new A()).start(); } } What is the result?()
A. A done
B. B done
C. A done B done
D. B done A done
E. There is no exception that the application will print anything.
F. The application outputs “A done” and “B done”, in no guaranteed order.
[单项选择] 现有: class Cat { Cat(int c) { System.out.print("cat" + c + " "); } } class SubCat extends Cat { SubCat(int c) { super(5); System.out.print("cable "); } SubCat() { this(4); } public static void main(String [] args) { SubCat s = new SubCat(); } } 结果为:()
A. cat5
B. cable
C. cable cat5
D. cat5 cable
[单项选择] 现有: class Pet implements Serializable { Collar c= new Collar(); } class Collar implements Serializable { collarPart cpl=new CollarPart ("handle"); CollarPart cp2=new CollarPart ("clip"); } class CollarPart implements Serializable() 如果Pet实例被序列化,则多少对象将被序列化?()
A. 0
B. 1
C. 2
D. 3
E. 4
F. 5
[单项选择] 现有: public class Pet() public class Cat extends Pet{) 执行代码 Cat c- new Cat(); Pet p= (Pet)c; 后下列哪项是正确的?()
A. Pet p=(Pet)c运行错误
B. Pet p=(Pet)c编译错误
C. Pet p= (Pet)c止常执行
D. 以上都不对
[单项选择] 现有: class Cat { Cat (int c) {System.out.print {"cat"+c+" "); } } class SubCat extends Cat { SubCat (int c){super (5); System.out.print ("cable");} SubCat() { this (4); } public static void main (String [] args) { SubCat s= new SubCat(); } } 结果为:()
A. cat5
B. cable
C. cat5 cable
D. cable cat5
[单项选择] public class Pet{ public void speak(){ System.out.print(“ Pet ”); } } public class Cat extends Pet{ public void speak(){ System.out.print(“ Cat ”); } } public class Dog extends Pet{ public void speak(){ System.out.print(“ Dog ”); } } 执行代码 Pet[] p = {new Cat(),new Dog(),new Pet()}; for(int i=0;i〈p.length;i++) p[i].speak(); 后输出的内容是哪项?()
A. Pet Pet Pet
B. Cat Cat Cat
C. Cat Dog Pet
D. Cat Dog Dog
[单项选择] public class Pet{ private String name; public Pet(){ System.out.print(1); } public Pet(String name){ System.out.print(2); } } public class Dog extends Pet{ public Dog(String name){ //这里隐藏了一句代码:super.pet(); System.out.print(3); } } 执行new Dog(“棕熊”);后程序输出是哪项?()
A. 23
B. 1 3
C. 123
D. 321
[单项选择] public class Pet{} public class Cat extends Pet{} 执行代码 Cat c = new Cat(); Pet p = (Pet)c; 下列哪项是正确的?
A. Pet p = (Pet)c正常执行
B. Pet p = (Pet)c编译错误
C. Pet p = (Pet)c运行错误
D. 以上都不对
[单项选择] public class Pet{ private String name; public Pet(){ System.out.print(1); } public Pet(String name){ System.out.print(2); } } public class Dog extends Pet{ public Dog(String name){ System.out.print(3); } } 执行new Dog(“棕熊”);后程序输出是哪项?()
A. 23
B. 13
C. 123
D. 321