Submitted by c-admin on Fri, 05/31/2019 - 06:46
Consider the following code:
interface Flyer{ }
class Bird implements Flyer { }
class Eagle extends Bird { }
class Bat { }
public class TestClass {
public static void main(String[] args) {
Flyer f = new Eagle();
Eagle e = new Eagle();
Bat b = new Bat();
if(f instanceof Bird) System.out.println("f is a Bird");
if(e instanceof Flyer) System.out.println("e is a Flyer");
if(b instanceof Flyer) System.out.println("f is a Bird");
}
}
What will be printed when the above code is compiled and run?
Select 1 option
A. It will not compile.
B. It will throw an exception when run.
C. f is a Bird
e is a Flyer
D. f is a Bird
E. e is a Flyer
Submitted by c-admin on Fri, 05/31/2019 - 06:43
Consider the following code:
interface Flyer{ }
class Bird implements Flyer { }
class Eagle extends Bird { }
class Bat { }
public class TestClass {
public static void main(String[] args) {
Flyer f = new Eagle();
Eagle e = new Eagle();
Bat b = new Bat();
if(f instanceof Flyer) System.out.println("f is a Flyer");
if(e instanceof Bird) System.out.println("e is a Bird");
if(b instanceof Bird) System.out.println("f is a Bird");
}
}
What will be printed when the above code is compiled and run?
Select 1 option
A. It will not compile.
B. It will throw an exception when run.
C. f is a Flyer
e is a Bird
D. f is a Flyer
E. e is a Bird
Submitted by c-admin on Fri, 05/31/2019 - 06:41
Which of the given statements are correct about the following code?
//Filename: TestClass.java
class TestClass{
public static void main(String[] args){
A a = new A();
B b = new B();
};
}
class A implements T1, T2{}
class B extends A implements T1{}
interface T1 { }
interface T2 { }
Select 4 options
A. (a instanceof T1) will return true.
B. (a instanceof T2) will return true.
C. (b instanceof T1) will return true.
D. (b instanceof T2) will return true.
E. (b instanceof A) will return false.
Submitted by c-admin on Fri, 05/31/2019 - 06:38
Consider :
class A {}
class B extends A {}
class C extends B {}
Which of these boolean expressions correctly identifies when an object 'o' actually refers to an object of class B and not of C?
Select 2 options
A. (o instanceof B) && (!(o instanceof A))
B. !((o instanceof A) || (o instanceof B))
C. (o instanceof B) && (!(o instanceof C)
D. ! ( !(o instanceof B) || (o instanceof C))
E. (o instanceof B) && !((o instanceof A) || (o instanceof C))
Submitted by c-admin on Fri, 05/31/2019 - 06:29
If a.equals(b) returns true, b instanceof ClassOfA must always be true.
(Assume that ClassOfA is the name of the class of the variable a.)
Select 1 option
A. True
B. False
Pages