Sail E0 Webinar

MCQs

Total Questions : 45 | Page 2 of 5 pages
Question 11. Determine output:
public class Test {
static void test(float x){
System.out.print("float");
}
static void test(double x){
System.out.print("double");
}
public static void main(String[] args){
test(99.9);
}
}
  1.    float
  2.    double
  3.    Compilation Error
  4.    Exception is thrown at runtime
 Discuss Question
Answer: Option B. -> double
Question 12. What would be the output of the following fraction of code ?
int Integer = 34 ;
char String = 'S' ;
System.out.print( Integer ) ;
System.out.print( String ) ;
  1.    Does not compile as Integer and String are API class names.
  2.    Throws exception.
  3.    34
  4.    S
  5.    34 S
 Discuss Question
Answer: Option E. -> 34 S
Question 13. The following fraction of code
double STATIC = 2.5 ;
System.out.println( STATIC );
  1.    Prints 2.5
  2.    Rraises an error as STATIC is used as a variable which is a keyword
  3.    Raises an exception
  4.    None of these
 Discuss Question
Answer: Option A. -> Prints 2.5
Question 14. What is the output of the following program?
public class Test{
static int x = 10 ;
public static void main(String[] a){
Test test = new Test( ) ;
Test test1 = new Test( ) ;
test.x += 1 ;
System.out.println( test.x + test1.x ) ;
}
}
  1.    20
  2.    21
  3.    22
  4.    Compilation Error
  5.    Throws Exception
 Discuss Question
Answer: Option C. -> 22
Question 15. What will be output of the following program code?
public class Test{
public static void main(String[] a){
short x = 10;
x = x*5;
System.out.print(x);
}
}
  1.    50
  2.    10
  3.    Compilation Error
  4.    None of these
 Discuss Question
Answer: Option C. -> Compilation Error
Question 16. Determine output:
public class Test{
int i = 34;
public static void main(String args[]){
Test t1 = new Test();
Test t2 = new Test();
t1.i = 65;
System.out.print(t1.i);
System.out.print(t2.i);
}
}
  1.    34 34
  2.    65 34
  3.    65 65
  4.    34 65
 Discuss Question
Answer: Option B. -> 65 34
Question 17. The following program:
public class Test{
static boolean isOK;
public static void main(String args[]){
System.out.print(isOK);
}
}
  1.    Prints true
  2.    Prints false
  3.    Will not compile as boolean is not initialized
  4.    Will not compile as boolean can never be static
 Discuss Question
Answer: Option B. -> Prints false
Question 18. What will the output of the following program?
public class Test{
public static void main(String args[]){
float f = (1 / 4) * 10;
int i = Math.round(f);
System.out.println(i);
}
}
  1.    2
  2.    0
  3.    3
  4.    2.5
  5.    25
 Discuss Question
Answer: Option B. -> 0
Question 19. In Java, the word true is ................
  1.    A Java keyword
  2.    A Boolean literal
  3.    Same as value 1
  4.    Same as value 0
 Discuss Question
Answer: Option B. -> A Boolean literal
Question 20. What is the output for the below code ?
class A{
int k;
boolean istrue;
static int p;
public void printValue(){
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
public class Test{
public static void main(String argv[]){
A a = new A();
a.printValue();
}
}
  1.    0 false 0
  2.    0 true 0
  3.    0 0 0
  4.    Compile error - static variable must be initialized before use.
  5.    None of these
 Discuss Question
Answer: Option A. -> 0 false 0

Latest Videos

Latest Test Papers