7.MCQ With Ans
7.MCQ With Ans
Answer:-C
Answer:-D
Answer:-D
Answer:-C
Answer:- 4
1|7.7MCQ
6.What is the output given code.
StringBuffer s1 = new StringBuffer("Quiz");
StringBuffer s2 = s1.reverse();
System.out.println(s2);
A. QuizziuQ
B. Quiz
C. ziuQQuiz
D. ziuQ
Answer:-D
Answer:-B
A. At run time
B. At compile time
C. Depends on the code
D. None
Answer:-A
A. abc
B. bc
C. bcd
D. cd
Answer:-B
2|7.7MCQ
10.Identify the return type of a method that does not return any value.
A. int
B. void
C. double
D. None
Answer:-B
A. 10
B. 11
C. Error
D. 13
Answer:-A
Answer:-D
Answer:-D
3|7.7MCQ
public static void main(String[]args)
{
A a;
System.out.println(a.i);
}
}
A. 0
B. Garbage value
C. Compilation error
D. Runtime error
Answer:-C
Answer:-B
Answer:-D
A. sum is 1020
B. sum is 30
4|7.7MCQ
C. airthmetic exception.
D. None of the above
Answer:-A
A. 40
B. 30
C. 20
D. 10
Answer:-A
A. -10
B. 10
C. Compile time error
D. None of the above.
Answer:-C
5|7.7MCQ
20.What the ouput of the below code snippet.
file name is sample.java
class Hai
{
public static void main(String[]args)
{
System.out.println("printed hai");
}
}
//javac sample.java
//java Hai
Answer:-C
A. 10
B. -5
6|7.7MCQ
C. 6
D. 7
E. 8
Answer:-E
Answer:-B
7|7.7MCQ
s1.a=25;
System.out.println(s2.a);
}
}
A. 10
B. 25
C. 10 25
D. 25 10
Answer:-A
A. 1,2
B. 2,3
C. 1,2,3
D. 1,2,3,4
Answer:-C
Answer:-C
8|7.7MCQ
27.Is static is a keyword.
A.True
B.False
Answer:-A
Answer:-A
Answer:-A
9|7.7MCQ
}
}
A. 30 30
B. 30 50
C. 30 40
D. 30 20
Answer:-C
Answer:-3
Answer:-A
10 | 7 . 7 M C Q
t1.x = 20;
System.out.print(t1.x + " ");
System.out.println(t2.x);
}
}
A. 10 10
B. 20 20
C. 10 20
D. 20 10
Answer:-B
Answer:-A
11 | 7 . 7 M C Q
A. 1 3 9
B. 1 2 3 … 9
C. 3 5 7 9 11 13 15 17 19
D. None
Answer:-C
Answer:-C
Answer:-B
12 | 7 . 7 M C Q
Answer:-B
Answer:-C
Answer:-D
42.How would you declare a variable that tells you that someone passed
a class?
Answer:-B
13 | 7 . 7 M C Q
44.Which function is used to input int value in Java using Scanner class?
A. scanner_object.nextInteger( )
B. scanner_object.nextInt( )
C. scanner_object.nextint( )
D. scanner_object.NextInt( )
Answer:-B
Answer:-A
46.Which package should you import to use the Scanner class in Java?
A. java.util
B. java.io
C. java.scanner
D. java.lang
E. java.system
Answer:-A
Answer:-C
48.Which method is used to read an integer input from the user using the
Scanner class?
A. readInt()
B. nextInt()
C. getInt()
D. scanInt()
14 | 7 . 7 M C Q
E. inputInt()
Answer:-B
Answer:-A
50.Which method is used to read a string input from the user using the
Scanner class?
A. readString()
B. nextString()
C. getString()
D. scanString()
E. nextLine()
Answer:-E
51.Which method checks if the Scanner object has another token available
in its input?
A. hasNext()
B. hasToken()
C. hasNextToken()
D. hasMore()
E. hasInput()
Answer:-A
52.Which method is used to read a double input from the user using the
Scanner class?
A. readDouble()
B. nextDouble()
C. getDouble()
D. scanDouble()
E. inputDouble()
Answer:-B
15 | 7 . 7 M C Q
53.What happens if you input a non-integer value when using the nextInt()
method of Scanner class?
Answer:-B
Answer:-C
55.Which method is used to read a single word without spaces from the
user using the Scanner class?
A. nextWord()
B. readWord()
C. scanWord()
D. next()
E. input()
Answer:-D
16 | 7 . 7 M C Q
}
A. Value of num2 is 2
B. Value of num2 is 1.5
C. Value of num2 is 2.0
D. Runtime error due to datatype conversion
Answer:-C
} else {
num2 = num2 + 1;
}
System.out.println(num1 + "," + num2);
}
}
A. 25,35
B. 25,34
C. 26,34
D. 26,36
Answer:-C
17 | 7 . 7 M C Q
}
A. true
B. false
C. true false
D. Compilation Error due to condition on wrong datatype.
Answer:-B
A. a = 32 b = 76
B. a = 33 b = 76
C. a = 33 b = 77
D. a = 32 b = 77
Answer:-B
18 | 7 . 7 M C Q
if (5 >= num3) {
if (num1 > 100 || num2 > 150) {
System.out.println("1");
}
} else if (num1 >= 100 && num2 > 150) {
System.out.println("2");
} else {
System.out.println("3");
}
}
}
A. 1
B. 2
C. 3
D. 1 3
Answer:-B
61.What should be the value of num1 and num2 to get the output as 2?
19 | 7 . 7 M C Q
62.What will be the output of the below program?
A. 11
B. 33
C. 44
D. 22
Answer:-C
20 | 7 . 7 M C Q
case -1:
j = 1;
case 2:
j = 2;
break;
default:
j = 0;
}
System.out.println("j = " + j);
}
}
A. j = 2
B. j = 1
C. j = 0
D. Compilation Error due to absence of break in first case block.
Answer:-A
64.Choose the correct option based on the code snippet given below.
Answer:-C
21 | 7 . 7 M C Q
65.What will be the output of the below program?
Answer:-D
22 | 7 . 7 M C Q
case 1:
System.out.println("Welcome");
case 2:
System.out.println("To");
case 3:
System.out.println("Infosys");
break;
}
}
}
A. Hello
B. Welcome
C. Welcome
To
Infosys
D. Compilation error as default must be the last case in the switch
block
Answer:-C
23 | 7 . 7 M C Q
Answer:-B
Answer:-D
24 | 7 . 7 M C Q
break;
}
System.out.println(j);
}
}
A. 3
B. 5
C. 4
D. 2
Answer:-A
Answer: A
Answer: B
72.What is the data type of the variable declared with the keyword float
in Java?
A) Integer
B) Floating-point
C) Character
D) Boolean
Answer:-B
25 | 7 . 7 M C Q
D) var
Answer: A
74. What will happen if you try to assign a value to a final variable
in Java after it has been initialized?
A) It will result in a compilation error
B) The program will throw a runtime exception
C) The final variable will be reinitialized with the new value
D) It will work without any issues
Answer: A
Answer: C
Answer: A
Answer:-B
26 | 7 . 7 M C Q
78.What is the maximum value that can be stored in a byte data type in
Java?
A) 255
B) 127
C) 32767
D) 2147483647
Answer: B
Answer: B
27 | 7 . 7 M C Q