0% found this document useful (0 votes)
30 views3 pages

Java MCQS

The document consists of multiple-choice questions related to Java programming concepts, including the String class, the final keyword, the this keyword, constructors, input methods, threading, identifiers, exception handling, abstraction, encapsulation, and interfaces. Each question presents four options, with some questions focusing on the characteristics and behaviors of Java elements. The content is designed to test knowledge of Java programming fundamentals.

Uploaded by

Jainesh Patel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Java MCQS

The document consists of multiple-choice questions related to Java programming concepts, including the String class, the final keyword, the this keyword, constructors, input methods, threading, identifiers, exception handling, abstraction, encapsulation, and interfaces. Each question presents four options, with some questions focusing on the characteristics and behaviors of Java elements. The content is designed to test knowledge of Java programming fundamentals.

Uploaded by

Jainesh Patel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1). Which of the following is true about the String class in Java?

a) String is mutable.
b) String is immutable.
c) String can be null.
d) String is an abstract class.

2). What does the final keyword do when applied to a variable?

a) Makes the variable accessible only in the current class.


b) Makes the variable value immutable.
c) Makes the variable visible in all classes.
d) Makes the variable public.

3). What does the this keyword refer to in Java?

a) The current class.


b) The current instance of the class.
c) The superclass of the current class.
d) The superclass instance of the current class.

4). Which of the following is not a valid type of constructor in Java?

a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) Static constructor

5). In the following code, what will super.x refer to?

class Animal {
int x = 5;
}
class Dog extends Animal {
int x = 10;
void display() {
[Link](super.x);
}
}

A) 5
B) 10
C) Compilation error
D) It will cause a runtime exception

6). Which of the following methods is used to read input from the keyboard in Java?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()

7). Which of the following can be used to create a thread in Java?

a) Implement the Runnable interface


b) Extend the Thread class
c) Both a and b
d) None of the above

8). Which of the following is not a valid identifier in Java?

a) MyVariable
b) _myVariable
c) $myVariable
d) 1stVariable

9). Which of the following is true about the finally block in Java?

a) It is executed only if no exception occurs.


b) It is executed if an exception occurs.
c) It is executed only if an exception is not caught.
d) It is never executed.

10). What is the default value of a double variable in Java?

a) 0.0
b) 0
c) null
d) undefined

OOPS Concept

1). Which of the following can be used to achieve abstraction in Java?

a) Interfaces
b) Abstract classes
c) Both a and b
d) None of the above

2). Which of the following statements about constructors is true in Java?


a) Constructors can have return types.
b) A constructor must have the same name as the class.
c) A constructor is invoked explicitly.
d) Constructors are inherited.

3). What will happen if a class doesn’t have a constructor in Java?

a) It will give a compilation error.


b) Java will automatically provide a default constructor.
c) The class will not be able to create objects.
d) The class will behave as an abstract class.

4). Which of the following statements is true regarding encapsulation in Java?

a) Encapsulation is the process of hiding data and providing methods to


access it.
b) Encapsulation is the same as inheritance.
c) Encapsulation does not allow access to private members of a class.
d) Encapsulation does not require constructors.

5). Which of the following is true about Java interfaces?

a) An interface can have concrete methods.


b) A class can implement multiple interfaces.
c) A class can extend multiple classes and implement interfaces.
d) An interface can have a constructor.

You might also like