MOCK Exam 1
MOCK Exam 1
a. Multithreading
b. Platform independent
c. Object Oriented programming
d. All of the above
a. 5
b. 4
c. Compilation error
d. X
d) Both a and c
5. Which of the following identifiers for variable declaration is invalid?
a. String name1
b. String 1_name
c. String name1_
d. String $1name
6. What will be the value of b that will be printed in the following block of code?
a) 17
b) 12
c) 10
d) 11
7. Which loop is used when you don’t know the how many repetition will be there?
a. While
b. For
c. Do-while
d. If-else
8. Which method of Scanner class is used to get double value from the user?
a. nextDouble()
b. nextInt()
c. nextdouble()
d. nextLine()
a. 3
b. 5
c. 4
d. Error
switch (day) {
case 1:
case 7:
System.out.println("Weekend");
case 2:
case 3:
case 4:
case 5:
System.out.println("Weekday");
break;
default:
System.out.println("Invalid day");
}
a) Weekend
b) Weekend Weekday
c) Invalid day
d) Weekday
11. What is the return type of a method that does not return any value?
a) void
b) int
c) String
class Animal {
public String makeSound(){
return "Animal makes sound";
}
public static void main(String[] args) {
Animal animal = new Animal();
System.out.println(animal.makeSound());
}
}
class Loop {
public static void main(String[] args) {
int[] numbers = {7,8,9,12,10};
for(int number : numbers){
System.out.println(number+",");
}
}
}
a. 7 8 9 12 10
b. 7,8,9,12,10,
c. 7891210
d. Error
1. class SelectionStatements
2. {
3. public static void main(String args[])
4. {
5. int var1 = 5;
6. int var2 = 6;
7. if ((var2 = 1) == var1)
8. System.out.print(var2);
9.
10. else
11. System.out.print(++var2);
12. }
}
a. Error
b. 2
c. 7
d. 6
15. Which of the following is not a valid declaration of an array?
17. Which of this method of class String is used to extract single character from a String
object?
A) chatat()
B) CHARAT()
C) ChatAt()
D) charAt()
a) Mutable
d) Both a and c
a) No
b) Yes
a) abstract
b) interface
c) define
d) class abstract
System.out.println(firstColor);
a) colors
b) null
c) Red
d) An error
a) Component
b) JComponent
c) JFrame
d) JPanel
b) To handle unexpected errors or exceptions that may occur during program execution.
d) To define a set of variables that can only be used within the block
26. Which is the super class of all java exceptions classes?
A) Exception
B) RuntimeException
C) Throwable
D) IOException
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
A) Compilation fails
B) Finally
C) The code runs with no output
D) An exception is thrown at runtime
a) Error
b) Calculator
c) 8
d) null
30. What is the difference between calling a static method and an instance method?
System.out.println("Chirp!");