Lakshya Education MCQs

Question: Determine output:
public class Test{
int a = 10;
public void method(int a){
a += 1;
System.out.println(++a);
}
public static void main(String args[]){
Test t = new Test();
t.method(3);
}
}
Options:
A.4
B.5
C.12
D.11
E.None of these
Answer: Option B

Submit Answer & Explaination

Earn Reward Points by submitting Detailed Explaination for this Question

More Questions on This Topic :

Question 1. What will be output of following program?
public class Test{
public static void main(String[] args){
byte b=127;
b++;
b++;
System.out.println(b);
}
}
  1.    2
  2.    129
  3.    -127
  4.    Compiler error
  5.    None of these
Answer: Option C
Question 2. What will be the output for the below code ?
1. public class Test{
2. int i=8;
3. int j=9;
4. public static void main(String[] args){
5. add();
6. }
7. public static void add(){
8. int k = i+j;
9. System.out.println(k);
10. }
11. }
  1.    17
  2.    0
  3.    Compilation fails with an error at line 5
  4.    Compilation fails with an error at line 8
  5.    None of these
Answer: Option D
Question 3. What is the output for the below code ?
1. public class Test{
2. public static void main(String[] args){
3. byte b = 6;
4. b+=8;
5. System.out.println(b);
6. b = b+7;
7. System.out.println(b);
8. }
9. }
  1.    14 21
  2.    14 13
  3.    Compilation fails with an error at line 6
  4.    Compilation fails with an error at line 4
  5.    None of these
Answer: Option C

Check all Questions in this Topic : Click HERE