Explore topic-wise MCQs in Testing Subject.

This section includes 657 Mcqs, each offering curated multiple-choice questions to sharpen your Testing Subject knowledge and support exam preparation. Choose a topic below to get started.

1.

What is true about Class.getInstance()?

A. Class.getInstance calls the constructor
B. Class.getInstance is same as new operator
C. Class.getInstance needs to have matching constructor
D. Class.getInstance creates object if class does not have any constructor
Answer» E.
2.

What is false about constructor?

A. Constructors cannot be synchronized in Java
B. Java does not provide default copy constructor
C. Constructor can be overloaded
D. “this” and “super” can be used in a constructor
Answer» D. “this” and “super” can be used in a constructor
3.

What would be the behaviour if this() and super() used in a method?

A. Runtime error
B. Throws exception
C. compile time error
D. Runs successfully
Answer» D. Runs successfully
4.

What is true about private constructor?

A. Private constructor ensures only one instance of a class exist at any point of time
B. Private constructor ensures multiple instances of a class exist at any point of time
C. Private constructor eases the instantiation of a class
D. Private constructor allows creating objects in other classes
Answer» B. Private constructor ensures multiple instances of a class exist at any point of time
5.

What is the output of this program? 1. class area 2. { 3. int width; 4. int length; 5. int area; 6. void area(int width, int length) 7. { 8. this.width = width; 9 this.length = length; 10. } 11. } 12. class Output 13. { 14. public static void main(String args[]) 15. { 16. area obj = new area(); 17. obj.area(5 , 6); 18. System.out.println(obj.length + " " + obj.width); 19. } 20. }

A. 0 0
B. 5 6
C. 6 5
D. 5 5
Answer» D. 5 5
6.

Which of the following statements are incorrect?

A. default constructor is called at the time of object declaration
B. Constructor can be parameterized
C. finalize() method is called when a object goes out of scope and is no longer needed
D. finalize() method must be declared protected
Answer» D. finalize() method must be declared protected
7.

What is the output of this program? 1. class box 2. { 3. int width; 4. int height; 5. int length; 6. int volume; 7. void finalize() 8. { 9. volume = width*height*length; 10. System.out.println(volume); 11. } 12. protected void volume() 13. { 14. volume = width*height*length; 15. System.out.println(volume); 16. } 17. } 18. class Output 19. { 20. public static void main(String args[]) 21. { 22. box obj = new box(); 23. obj.width=5; 24. obj.height=5; 25. obj.length=6; 26. obj.volume(); 27. } 28. }

A. 150
B. 200
C. Run time error
D. Compilation error
Answer» B. 200
8.

What is the output of this program? 1. class San 2. { 3. San()throws IOException 4. { 5. } 6. } 7. class Foundry extends San 8. { 9. Foundry() 10. { 11. } 12. public static void main(String[]args) 13. { 14. } 15. }

A. compile time error
B. run time error
C. compile and runs fine
D. unreported exception java.io.IOException in default constructor
Answer» B. run time error
9.

1. class box 2. { 3. int width; 4. int height; 5. int length; 6. int volume; 7. box() 8. { 9. width = 5; 10. height = 5; 11. length = 6; 12. } 13. void volume() 14. { 15. volume = width*height*length; 16. } 17. } 18. class constructor_output 19. { 20. public static void main(String args[]) 21. { 22. box obj = new box(); 23. obj.volume(); 24. System.out.println(obj.volume); 25. } 26. }

A. 100
B. 150
C. 200
D. 250
Answer» C. 200
10.

Which function is used to perform some action when the object is to be destroyed?

A. finalize()
B. delete()
C. main()
D. none of the mentioned
Answer» B. delete()
11.

Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed?

A. delete
B. free
C. new
D. none of the mentioned
Answer» E.
12.

Which of the following is a method having same name as that of its class?

A. finalize
B. delete
C. class
D. constructor
Answer» E.
13.

Which keyword is used by method to refer to the object that invoked it?

A. import
B. catch
C. abstract
D. this
Answer» E.
14.

What is the return type of Constructors?

A. int
B. float
C. void
D. none of the mentioned
Answer» E.
15.

What is the output of this program? class area { int width; int length; int volume; area() { width=5; length=6; } void volume() { volume = width*length*height; } } class cons_method { public static void main(String args[]) { area obj = new area(); obj.volume(); System.out.println(obj.volume); } }

A. 0
B. 1
C. 30
D. error
Answer» E.
16.

In the below code, which call to sum() method is appropriate? class Output { public static int sum(int ...x) { return; } static void main(String args[]) { sum(10); sum(10,20); sum(10,20,30); sum(10,20,30,40); } }

A. only sum(10)
B. only sum(10,20)
C. only sum(10) & sum(10,20)
D. all of the mentioned
Answer» E.
17.

What is the output of this program? class box { int width; int height; int length; int volume; void volume() { volume = width*height*length; } } class Output { public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(); System.out.println(obj.volume); } }

A. 0
B. 1
C. 25
D. 26
Answer» D. 26
18.

What is the output of this program? class equality { int x; int y; boolean isequal() { return(x == y); } } class Output { public static void main(String args[]) { equality obj = new equality(); obj.x = 5; obj.y = 5; System.out.println(obj.isequal()); } }

A. false
B. true
C. 0
D. 1
Answer» C. 0
19.

What is the output of this program? class box { int width; int height; int length; int volume; void volume(int height, int length, int width) { volume = width*height*length; } } class Prameterized_method { public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(3,2,1); System.out.println(obj.volume); } }

A. 0
B. 1
C. 6
D. 25
Answer» D. 25
20.

Which method can be defined only once in a program?

A. main method
B. finalize method
C. static method
D. private method
Answer» B. finalize method
21.

Which of the following is a method having same name as that of it’s class?

A. finalize
B. delete
C. class
D. constructor
Answer» E.
22.

What is the process of defining more than one method in a class differentiated by method signature?

A. Function overriding
B. Function overloading
C. Function doubling
D. None of the mentioned
Answer» C. Function doubling
23.

What is the return type of a method that does not returns any value?

A. int
B. float
C. void
D. double
Answer» D. double
24.

What is the output of this program? class box { int width; int height; int length; } class mainclass { public static void main(String args[]) { box obj = new box(); System.out.println(obj); } }

A. 0
B. 1
C. Runtime error
D. classname@hashcode in hexadecimal form
Answer» E.
25.

What is the output of this program? class box { int width; int height; int length; } class mainclass { public static void main(String args[]) { box obj1 = new box(); box obj2 = new box(); obj1.height = 1; obj1.length = 2; obj1.width = 1; obj2 = obj1; System.out.println(obj2.height); } }

A. 1
B. 2
C. Runtime error
D. Garbage value
Answer» B. 2
26.

What is the output of this program? class box { int width; int height; int length; } class mainclass { public static void main(String args[]) { box obj = new box(); obj.width = 10; obj.height = 2; obj.length = 10; int y = obj.width * obj.height * obj.length; System.out.print(y); } }

A. 12
B. 200
C. 400
D. 100
Answer» C. 400
27.

Which of the following statements is correct?

A. Public method is accessible to all other classes in the hierarchy
B. Public method is accessible only to subclasses of its parent class
C. Public method can only be called by object of its class
D. public method can be accessed by calling object of the public class
Answer» B. Public method is accessible only to subclasses of its parent class
28.

What is the output of this program? class main_class { public static void main(String args[]) { int x = 9; if (x == 9) { int x = 8; System.out.println(x); } } }

A. 9
B. 8
C. Compilation error
D. Runtime error
Answer» D. Runtime error
29.

Which of these operators is used to allocate memory for an object?

A. malloc
B. alloc
C. new
D. give
Answer» D. give
30.

Which of the following is a valid declaration of an object of class Box?

A. Box obj = new Box();
B. Box obj = new Box;
C. Box obj = new Box;
D. new Box obj;
Answer» B. Box obj = new Box;
31.

Which of these keywords is used to make a class?

A. class
B. struct
C. int
D. none of the mentioned
Answer» B. struct
32.

What is the stored in the object obj in following lines of code? box obj;

A. Memory address of allocated memory of object
B. NULL
C. Any arbitrary pointer
D. Garbage
Answer» C. Any arbitrary pointer
33.

What is use of interpreter?

A. They convert bytecode to machine language code
B. They read high level code and execute them
C. They are intermediated between JIT and JVM
D. They are intermediated between JIT and JVM
Answer» C. They are intermediated between JIT and JVM
34.

How can we identify whether a compilation unit is class or interface from a .class file?

A. Java source file header
B. Extension of compilation unit
C. We cannot differentiate between class and interface
D. The class or interface name should be postfixed with unit type
Answer» B. Extension of compilation unit
35.

What is the extension of compiled java classes?

A. .class
B. .java
C. .txt
D. .js
Answer» B. .java
36.

What is the extension of java code files?

A. .class
B. .java
C. .txt
D. .js
Answer» C. .txt
37.

Which of the below is invalid identifier with main method?

A. public
B. Static
C. private
D. Final
Answer» D. Final
38.

Which statement is true about java?

A. Platform independent programming language
B. Platform dependent programming language
C. Code dependent programming language
D. Sequence dependent programming language
Answer» B. Platform dependent programming language
39.

Which component is responsible to optimize bytecode to machine code?

A. JVM
B. JDK
C. JIT
D. JRE
Answer» D. JRE
40.

Which component is responsible to run java program?

A. JVM
B. JDK
C. JIT
D. JRE
Answer» E.
41.

Which component is responsible for converting bytecode into machine specific code?

A. JVM
B. JDK
C. JIT
D. JRE
Answer» B. JDK
42.

Which component is used to compile, debug and execute java program?

A. JVM
B. JDK
C. JIT
D. JRE
Answer» C. JIT
43.

Method overriding is combination of inheritance and polymorphism?

A. True
B. False
Answer» B. False
44.

What is it called where object has its own lifecycle and child object cannot belong to another parent object?

A. Aggregation
B. Composition
C. Encapsulation
D. Association
Answer» B. Composition
45.

What is it called where child object gets killed if parent object is killed?

A. Aggregation
B. Composition
C. Encapsulation
D. Association
Answer» C. Encapsulation
46.

What is it called if an object has its own lifecycle and there is no owner?

A. Aggregation
B. Composition
C. Encapsulation
D. Association
Answer» E.
47.

Which concept of Java is achieved by combining methods and attribute into a class?

A. Encapsulation
B. Inheritance
C. Polymorphism
D. Abstraction
Answer» B. Inheritance
48.

Which concept of Java is a way of converting real world objects in terms of class?

A. Polymorphism
B. Encapsulation
C. Abstraction
D. Inheritance
Answer» D. Inheritance
49.

When Overloading does not occur?

A. More than one method with same name but different method signature and different number or type of parameters
B. More than one method with same name, same signature but different number of signature
C. More than one method with same name, same signature, same number of parameters but different type
D. More than one method with same name, same number of parameters and type but different signature
Answer» E.
50.

When does method overloading is determined?

A. At run time
B. At compile time
C. At coding time
D. At execution time
Answer» C. At coding time