Submitted by heartin on Sun, 09/13/2015 - 06:48
What will be the result of compiling and running the following code?
Select 1 option
class Base{
public short getValue(){ return 1; } //1
}
class Base2 extends Base{
public byte getValue(){ return 2; } //2
}
public class TestClass{
public static void main(String[] args){
Base b = new Base2();
System.out.println(b.getValue()); //3
}
}
A. It will print 1
B. It will print 2.
C. Compile time error at //1
D. Compile time error at //2
E. Compile time error at //3
Submitted by heartin on Sun, 09/13/2015 - 05:29
Given
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 heartin on Sat, 09/12/2015 - 22:43
Given:
public class ExceptionCheck {
static int i = 10;
public static void main (String[] argds)
{
System.out.println(myMethod());
System.out.println(i);
}
public static int myMethod()
{
try{
throw new Exception();
}
catch(Exception e)
{
return i;
}
finally{
i = 12;
return i;
}
return i;
}
}
Select 1 option
A. Compilation Fail
B. Print 10 and 12.
C. Print 10 and 10.
D. Print 12 and 12.
Submitted by heartin on Sat, 09/12/2015 - 22:42
Given:
public class ExceptionCheck {
static int i = 10;
public static void main (String[] argds)
{
System.out.println(myMethod());
System.out.println(i);
}
public static int myMethod()
{
try{
throw new Exception();
}
catch(Exception e)
{
return i;
}
finally{
i = 12;
return i;
}
}
}
Select 1 option
A. Compilation Fail
B. Print 10 and 12.
C. Print 10 and 10.
D. Print 12 and 12.
Submitted by heartin on Sat, 09/12/2015 - 22:42
Given:
public class ExceptionCheck {
static int i = 10;
public static void main (String[] argds)
{
System.out.println(myMethod());
System.out.println(i);
}
public static int myMethod()
{
try{
throw new Exception();
}
catch(Exception e)
{
return i;
}
finally{
i = 12;
}
}
}
Select 1 option
A. Compilation Fail
B. Print 10 and 12.
C. Print 10 and 10.
D. Print 12 and 12.
Pages