Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Set-4 [13/08/2020]

1. What will be the output?


public class Xyz{
public static void main(String args[]){
int a = 402;
double b = 402.256;
System.out.print((a%10)+" "+(b%10));
}
}
A. 402 402.256 B. 2 2.55 C. 40.2 40.25 D. 2 2.255999999999972
Answer: Option D

2. What will be the output after compiling and running following code?
1. class Main{
2. public static void main(String... args){
3. int x =2;
4. x *= 3 + 7;
5. System.out.println(x);
6. }
7. }
A. 22 B. 50 C. 20 D. Compilation fails.
Answer: Option C

3. Determine output:
public class Abc{
public static void main(String... args){
int a=1 , b=2, c=3;
System.out.println("Value is "+ b + c);
System.out.println(a + b + c);
System.out.println("String " + (b+c));
}
}
A. Value is 5 6 String 5 B. Value is 23 6 String 5
C. Value is 23 5 String D. Compilation fails
Answer: Option B

4. Determine output:
public class Abc{
static int i = 5;
public static void main(String... args){
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
System.out.println(++i+i++);
}
}
A. 5 6 7 16 B. 6 7 6 16
C. 6 6 6 16 D. 5 6 6 16
Answer: Option A

5. The output of the following fraction of code is


public class Test{
public static void main(String args[]){
String s1 = new String("Hello");
String s2 = new String("Hellow");
System.out.println(s1 = s2);
System.out.println(s1 == s2);

}
}
A. Hello true B. Hello false C. Hellow true D. Hellow false
Answer: Option C

6.What will be the output of the following program code?


class My{
public static void main(String args[]){
String str1 = new String("OKAY");
String str2 = new String(str1);
System.out.println(str1 == str2);
}
}
A. true B. 0 C. false D. 1
Answer: Option C

7. What will be the output of the following program?


public class StrEq{
public static void main(String args[]){
String s1 = "java";
String s2 = new String( "java");
System.out.println(s1.equals(s2));
System.out.println(s1 == s2);
}
}
A. false true B. false false
C. true false D. true true
Answer: Option C

8. Determine output:
public class StrcharAt{
public static void main(String args[]){
String s1 = “SITHA” ;
String s2 = “RAMA”;
System.out.println(s1.charAt(0) > s2.charAt(0));
}
}
A. true B. false C. 0
D. Compilation error E. Throws Exception
Answer: Option A

9. What could be output of the following fragment of code?


public class MyStr{
public static void main(String args[]){
String x = "hellow";
int y = 5;
System.out.println(x += y);
}
}
A. Throws an exception B. 5hellow C. hellow5 D. Compilation error
Answer: Option C

10. What will be the output of the following program?


public class StrConcat{
public static void main(String args[]){
String str1 = "one";
String str2 = "two";
str1.concat(str2);
System.out.println(str1);
}
}
A. onetwo B. two C. one D. twoone
Answer: Option A

You might also like