Submitted by c-admin on Tue, 05/28/2019 - 00:19
In which of these variable declarations, will the variable remain uninitialized unless explicitly initialized?
Select 1 option
A. Declaration of an instance variable of type int.
B. Declaration of a static class variable of type float.
C. Declaration of a local variable of type float.
D. Declaration of a static class variable of class Object
E. Declaration of an instance variable of class Object.
Submitted by c-admin on Tue, 05/28/2019 - 00:17
What will the following program print?
public class TestClass{
public static void main(String[] args){
unsigned byte b = 0;
b--;
System.out.println(b);
}
}
Select 1 option
A. 0
B. -1
C. 255
D. -128
E. It will not compile.
Submitted by c-admin on Tue, 05/28/2019 - 00:14
What happens when you try to compile and run the following class...
public class TestClass{
public static void main(String[] args) throws Exception{
int a = Integer.MIN_VALUE;
int b = -a;
System.out.println( a+ " "+b);
}
}
Select 1 option
A. It throws an OverFlowException.
B. It will print two same negative numbers.
C. It will print two different negative numbers.
D. It will print one negative and one positive number of same magnitude.
E. It will print one negative and one positive number of different magnitude.
Submitted by c-admin on Tue, 05/28/2019 - 00:11
What happens when you try to compile and run the following program?
public class CastTest{
public static void main(String args[ ] ){
byte b = -128 ;
int i = b ;
b = (byte) i;
System.out.println(i+" "+b);
}
}
Select 1 option
A. The compiler will refuse to compile it because i and b are of different types cannot be assigned to each other.
B. The program will compile and will print -128 and -128 when run.
C. The compiler will refuse to compile it because -128 is outside the legal range of values for a byte.
D. The program will compile and will print 128 and -128 when run.
E. The program will compile and will print 255 and -128 when run.
Submitted by c-admin on Tue, 05/28/2019 - 00:06
What will be the result of attempting to compile and run the following code?
public class InitClass{
public static void main(String args[ ] ){
InitClass obj = new InitClass(5);
}
int m;
static int i1 = 5;
static int i2 ;
int j = 100;
int x;
public InitClass(int m){
System.out.println(i1 + " " + i2 + " " + x + " " + j + " " + m);
}
{ j = 30; i2 = 40; } // Instance Initializer
static { i1++; } // Static Initializer
}
Select 1 option
A. The code will fail to compile, since the instance initializer tries to assign a value to a static member.
B. The code will fail to compile, since the member variable x will be uninitialized when it is used.
C. The code will compile without error and will print 6, 40, 0, 30, 5 when run.
D. The code will compile without error and will print 5, 0, 0, 100, 5 when run.
E. The code will compile without error and will print 5, 40, 0, 30, 0 when run.
Pages