Submitted by c-admin on Fri, 05/31/2019 - 05:53
Given the following interface definition, which definitions are valid?
interface I1{
void setValue(String s);
String getValue(); }
Select 2 options
A. class A extends I1{
String s;
void setValue(String val) { s = val; }
String getValue() { return s; } }
B. interface I2 extends I1{
void analyse(); }
C. abstract class B implements I1{
int getValue(int i) { return 0; } }
D. interface I3 implements I1{
void perform_work(); }
Submitted by c-admin on Fri, 05/31/2019 - 05:52
Which one of these is a proper definition of a class Car that cannot be sub-classed?
Select 1 option
A. class Car { }
B. abstract class Car { }
C. native class Car { }
D. static class Car { }
E. final class Car { }
Submitted by c-admin on Fri, 05/31/2019 - 05:50
Note: This question may be considered too advanced for this exam.
Given the declaration :
interface Worker { void perform_work(); }
which of the following methods/classes are valid?
Select 2 options
A. Worker getWorker(int i){
return new Worker(){
public void perform_work() {
System.out.println(i); } }; }
B. Worker getWorker(final int i){
return new Worker() {
public void perform_work() {
System.out.println(i); } }; }
C. Worker getWorker(int i){
int x = i;
class MyWorker implements Worker {
public void perform_work() {
System.out.println(x); } };
return new MyWorker(); }
D. Worker getWorker(final int i){
class MyWorker implements Worker {
public void perform_work() {
System.out.println(i); } };
return new MyWorker(); }
Submitted by c-admin on Fri, 05/31/2019 - 05:49
What, if anything, is wrong with the following code?
// Filename: TestClass.java
class TestClass implements T1, T2{
public void m1(){} }
interface T1{
int VALUE = 1;
void m1(); }
interface T2{
int VALUE = 2;
void m1(); }
Select 1 option
A. TestClass cannot implement them both because it leads to ambiguity.
B. There is nothing wrong with the code.
C. The code will work fine only if VALUE is removed from one of the interfaces.
D. The code will work fine only if m1() is removed from one of the interfaces.
E. None of the above.
Submitted by c-admin on Fri, 05/31/2019 - 05:47
Given the following code, which statements are true?
interface Automobile { String describe(); }
class FourWheeler implements Automobile{
String name;
public String describe(){ return " 4 Wheeler " + name; }
}
class TwoWheeler extends FourWheeler{
String name;
public String describe(){ return " 2 Wheeler " + name; }
}
Select 3 options
A. An instance of TwoWheeler is also an instance of FourWheeler.
B. An instance of TwoWheeler is a valid instance of Automobile.
C. The use of inheritance is not justified here because a TwoWheeler is not really a FourWheeler.
D. The code will compile only if name is removed from TwoWheeler.
E. The code will fail to compile.
Pages