Which two demonstrate an “is a” relationship? ()
Apublic interface Person{} public class Employee extends Person{}
Bpublic interface Shape{} public class Employee extends Shape{}
Cpublic interface Color{} public class Employee extends Color{}
Dpublic class Species{} public class Animal (private Species species;)
Einterface Component{} Class Container implements Component ( Private Component[ ] children; )
相关问题推荐
-
public class Yippee2 { static public void main(String [] yahoo) { for(int x= 1; xSystem.out.print(yahoo[x] + “ “); } } } and the command line invocation: java Yippee2 a b c What is the result?()
A、a b
B、b c
C、a b c
D、 Compilation fails.
E、 An exception is thrown at runtime.
-
Consider the following class: class Test(int i) { void test(int i) { System.out.println(“I am an int.”); } void test(String s) { System.out.println(“I am a string.”); } public static void main(String args) { Test t=new Test(); char ch=“y”; t.test(ch); } } Which of the statements below is true?()
A、 Line 5 will not compile, because void methods cannot be overridden.
B、 Line 12 will not compile, because there is no version of test() that rakes a charargument.
C、 The code will compile but will throw an exception at line 12.
D、 The code will compile and produce the following output: I am an int.
E、 The code will compile and produce the following output: I am a String.
-
Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5?()
Amove the line 12 print statement into the foo() method
Bchange line 7 to public synchronized void go(){
Cchange the variable declaration on line 2 to private volatile int x;
Dwrap the code inside the foo() method with a synchronized(this) block
Ewrap the for loop code inside the go() method with a synchronized block synchronized(this){//for loop code here}
-
public class X { public X aMethod() { return this;} } public class Y extends X { } Which two methods can be added to the definition of class Y?()
Apublic void aMethod() {}
Bprivate void aMethod() {}
Cpublic void aMethod(String s) {}
Dprivate Y aMethod() { return null; }
Epublic X aMethod() { return new Y(); }
-
Assume that country is set for each class. Given: 10. public class Money { 11. private String country, name; 12. public getCountry() { return country; } 13.} and: 24. class Yen extends Money { 25. public String getCountry() { return super.country; } 26. } 27. 28. class Euro extends Money { 29. public String getCountry(String timeZone) { 30. return super.getCountry(); 31. } 32. } Which two are correct?()
AYen returns correct values.
BEuro returns correct values.
CAn exception is thrown at runtime.
DYen and Euro both return correct values.
ECompilation fails because of an error at line 25.
FCompilation fails because of an error at line 30.