Java Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Java Programming MCQ (Multiple Choice Questions)

 Que-  Which of the following operators can operate on a boolean variable?    1. &&    2. ==    3. ?:    4. +=

a. 3 & 2

b. 1 & 4

c. 1, 2 & 4

d. 1, 2 & 3


Answer- 1, 2 & 3


Que-  What is true about protected constructor?

a. Protected constructor can be called directly

b. Protected constructor can only be called using super()

c. Protected constructor can be used outside package

d. protected constructor can be instantiated even if child is in a different package


Answer- Protected constructor can only be called using super()


Que-  What is not the use of "this" keyword in Java?

a. Passing itself to another method

b. Calling another constructor in constructor chaining

c. Referring to the instance variable when local variable has the same name

d. Passing itself to method of the same class


Answer- Passing itself to method of the same class


Que-  What would be the behaviour if one parameterized constructor is explicitly defined?

a. Compilation error

b. Compilation succeeds

c. Runtime error

d. Compilation succeeds but at the time of creating object using default constructor, it throws compilation error


Answer- Compilation succeeds but at the time of creating object using default constructor, it throws compilation error


Que-  What would be behaviour if the constructor has a return type?

a. Compilation error

b. Runtime error

c. Compilation and runs successfully

d. Only String return type is allowed


Answer- Compilation error


Que-  Which of the following has the highest memory requirement?

a. Heap

b. Stack

c. JVM

d. Class


Answer- JVM


Que-  Where is a new object allocated memory?

a. Young space

b. Old space

c. Young or Old space depending on space availability

d. JVM


Answer- Young space


Que-  Which of the following is a garbage collection technique?

a. Cleanup model

b. Mark and sweep model

c. Space management model

d. Sweep model


Answer- Mark and sweep model


Que-  What is -Xms and -Xmx while starting jvm?

a. Initial; Maximum memory

b. Maximum; Initial memory

c. Maximum memory

d. Initial memory


Answer- Initial; Maximum memory


Que-  Which exception is thrown when java is out of memory?

a. MemoryFullException

b. MemoryOutOfBoundsException

c. OutOfMemoryError

d. MemoryError


Answer- OutOfMemoryError


Que-  How to get prints of shared object memory maps or heap memory maps for a given process?

a. jmap

b. memorymap

c. memorypath

d. jvmmap


Answer- jmap


Que-  What happens to the thread when garbage collection kicks off?

a. The thread continues its operation

b. Garbage collection cannot happen until the thread is running

c. The thread is paused while garbage collection runs

d. The thread and garbage collection do not interfere with each other


Answer- The thread is paused while garbage collection runs


Que-  Which of the below is not a Java Profiler?

a. JVM

b. JConsole

c. JProfiler

d. Eclipse Profiler


Answer- JVM


Que-  Which of the below is not a memory leak solution?

a. Code changes

b. JVM parameter tuning

c. Process restart

d. GC parameter tuning


Answer- Process restart


Que-  What is the process of defining two or more methods within same class that have same name but different parameters declaration?

a. method overloading

b. method overriding

c. method hiding

d. none of the mentioned


Answer- method overloading


Que-  Which of these can be overloaded?

a. Methods

b. Constructors

c. All of the mentioned

d. None of the mentioned


Answer- All of the mentioned


Que-  Which of these is correct about passing an argument by call-by-value process?

a. Copy of argument is made into the formal parameter of the subroutine

b. Reference to original argument is passed to formal parameter of the subroutine

c. Copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument

d. Reference to original argument is passed to formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument


Answer- Copy of argument is made into the formal parameter of the subroutine


Que-  What is the process of defining a method in terms of itself, that is a method that calls itself?

a. Polymorphism

b. Abstraction

c. Encapsulation

d. Recursion


Answer- Recursion


Que-  Which of these access specifiers must be used for main() method?

a. private

b. public

c. protected

d. none of the mentioned


Answer- public


Que-  Which of these is used to access a member of class before object of that class is created?

a. public

b. private

c. static

d. protected


Answer- static


Que-  Which of these is used as a default for a member of a class if no access specifier is used for it?

a. private

b. public

c. public, within its own package

d. protected


Answer- private


Que-  What is the process by which we can control what parts of a program can access the members of a class?

a. Polymorphism

b. Abstraction

c. Encapsulation

d. Recursion


Answer- Encapsulation


Que-  Which of the following statements are incorrect?

a. public members of class can be accessed by any code in the program

b. private members of class can only be accessed by other members of the class

c. private members of class can be inherited by a subclass, and become protected members in subclass

d. protected members of a class can be inherited by a subclass, and become private members of the subclass


Answer- private members of class can be inherited by a subclass, and become protected members in subclass


Que-  Which of these access specifier must be used for class so that it can be inherited by another subclass?

a. public

b. private

c. protected

d. none of the mentioned


Answer- public


Que-  Which one of the following is not an access modifier?

a. Public

b. Private

c. Protected

d. Void


Answer- Void


Que-  All the variables of class should be ideally declared as?

a. private

b. public

c. protected

d. default


Answer- private


Que-  Which of the following modifier means a particular variable cannot be accessed within the package?

a. private

b. public

c. protected

d. default


Answer- private


Que-  How can a protected modifier be accessed?

a. accessible only within the class

b. accessible only within package

c. accessible within package and outside the package but through inheritance only

d. accessible by all


Answer- accessible within package and outside the package but through inheritance only


Que-  What happens if constructor of class A is made private?

a. Any class can instantiate objects of class A

b. Objects of class A can be instantiated only within the class where it is declared

c. Inherited class can instantiate objects of class A

d. classes within the same package as class A can instantiate objects of class A


Answer- Objects of class A can be instantiated only within the class where it is declared


Que-  All the variables of interface should be?

a. default and final

b. default and static

c. public, static and final

d. protect, static and final


Answer- public, static and final


Que-  What is true of final class?

a. Final class cause compilation failure

b. Final class cannot be instantiated

c. Final class cause runtime failure

d. Final class cannot be inherited


Answer- Final class cannot be inherited


Que-  How many copies of static and class variables are created when 10 objects are created of a class?

a. 1, 10

b. 10, 10

c. 10, 1

d. 1, 1


Answer- 1, 10


Que-  Can a class be declared with a protected modifier.

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-FALSE


Que-  Which is the modifier when there is none mentioned explicitly?

a. protected

b. private

c. public

d. default


Answer- default


Que-  Arrays in Java are implemented as?

a. class

b. object

c. variable

d. none of the mentioned


Answer- object


Que-  Which of these keywords is used to prevent content of a variable from being modified?

a. final

b. last

c. constant

d. static


Answer- final


Que-  Which of these cannot be declared static?

a. class

b. object

c. variable

d. method


Answer- object

Previous Post Next Post