Explore topic-wise MCQs in Technical Programming.

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

1401.

What is the output of this program? class access { static int x; void increment() { x++; } } class static_use { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.increment(); obj2.increment(); System.out.println(obj1.x + " " + obj2.x); } }

A. 1 2
B. 1 1
C. 2 2
D. Compilation Error
Answer» D. Compilation Error
1402.

What is the output of this program? class access { public int x; static int y; void cal(int a, int b) { x += a ; y += b; } } class static_specifier { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.y = 0; obj1.cal(1, 2); obj2.x = 0; obj2.cal(2, 3); System.out.println(obj1.x + " " + obj2.y); } }

A. 1 2
B. 2 3
C. 3 2
D. 1 5
Answer» E.
1403.

Which of these methods must be made static?

A. main()
B. delete()
C. run()
D. finalize()
Answer» B. delete()
1404.

Which of these cannot be declared static?

A. class
B. Object
C. variable
D. Method
Answer» C. variable
1405.

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

A. Final
B. Last
C. constant
D. static
Answer» B. Last
1406.

Arrays in Java are implemented as?

A. class
B. object
C. variable
D. none of the mentioned
Answer» C. variable
1407.

Which is the modifier when there is none mentioned explicitly?

A. protected
B. Private
C. public
D. default
Answer» E.
1408.

Can a class be declared with protected modifier?

A. True
B. False
Answer» C.
1409.

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» B. 10, 10
1410.

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» E.
1411.

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» D. protect, static and final
1412.

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» C. Inherited class can instantiate objects of class A
1413.

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» D. accessible by all
1414.

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

A. private
B. public
C. protected
D. default
Answer» B. public
1415.

All the variables of class should be ideally declared as ?

A. private
B. public
C. protected
D. Default
Answer» B. public
1416.

Which one of the following is not an access modifier?

A. Public
B. Private
C. Protected
D. Void
Answer» E.
1417.

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» B. private
1418.

What is the output of this program? class static_out { static int x; static int y; void add(int a, int b) { x = a + b; y = x + b; } } class static_use { public static void main(String args[]) { static_out obj1 = new static_out(); static_out obj2 = new static_out(); int a = 2; obj1.add(a, a + 1); obj2.add(5, a); System.out.println(obj1.x + " " + obj2.y); } }

A. 7 7
B. 6 6
C. 7 9
D. 9 7
Answer» D. 9 7
1419.

What is the output of this program? class access { public int x; private int y; void cal(int a, int b) { x = a + 1; y = b; } void print() { system.out.println(" " + y); } } class access_specifier { public static void main(String args[]) { access obj = new access(); obj.cal(2, 3); System.out.println(obj.x); obj.print(); } }

A. 2 3
B. 3 3
C. Runtime Error
D. Compilation Error
Answer» C. Runtime Error
1420.

What is the output of this program? class access { public int x; private int y; void cal(int a, int b) { x = a + 1; y = b; } } class access_specifier { public static void main(String args[]) { access obj = new access(); obj.cal(2, 3); System.out.println(obj.x + " " + obj.y); } }

A. 3 3
B. 2 3
C. Runtime Error
D. Compilation Error
Answer» D. Compilation Error
1421.

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» D. Recursion
1422.

Which of these is used as 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» B. public
1423.

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

A. Public
B. Private
C. static
D. protected
Answer» D. protected
1424.

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

A. private
B. public
C. protected
D. none of the mentioned
Answer» C. protected
1425.

What is the output of this program? class test { int a; int b; test(int i, int j) { a = i; b = j; } void meth(test o) { o.a *= 2; O.b /= 2; } } class Output { public static void main(String args[]) { test obj = new test(10 , 20); obj.meth(obj); System.out.println(obj.a + " " + obj.b); } }

A. 10 20
B. 20 10
C. 20 40
D. 40 20
Answer» C. 20 40
1426.

What is the output of this program? class test { int a; int b; void meth(int i , int j) { i *= 2; j /= 2; } } class Output { public static void main(String args[]) { test obj = new test(); int a = 10; int b = 20; obj.meth(a , b); System.out.println(a + " " + b); } }

A. 10 20
B. 20 10
C. 20 40
D. 40 20
Answer» B. 20 10
1427.

What is the output of this program? class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x = 0; this.y = 0; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 2; double b = 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + " " + obj.y); } }

A. 6 6
B. 6.4 6.4
C. 6.4 6
D. 4 6.4
Answer» E.
1428.

What is the output of this program? class overload { int x; int y; void add(int a) { x = a + 1; } void add(int a , int b) { x = a + 2; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 0; obj.add(6, 7); System.out.println(obj.x); } }

A. 6
B. 7
C. 8
D. 9
Answer» D. 9
1429.

What is the output of this program? class overload { int x; int y; void add(int a) { x = a + 1; } void add(int a, int b) { x = a + 2; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 0; obj.add(6); System.out.println(obj.x); } }

A. 5
B. 6
C. 7
D. 8
Answer» D. 8
1430.

What is the output of the following code? class San { public void m1 (int i,float f) { System.out.println(" int float method"); } public void m1(float f,int i); { System.out.println("float int method"); } public static void main(String[]args) { San s=new San(); s.m1(20,20); } }

A. int float method
B. float int method
C. compile time error
D. run time error
Answer» D. run time error
1431.

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» E.
1432.

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» B. Reference to original argument is passed to formal parameter of the subroutine
1433.

Which of these can be overloaded?

A. Methods
B. Constructors
C. All of the mentioned
D. None of the mentioned
Answer» D. None of the mentioned
1434.

What is 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» B. method overriding
1435.

Garbage Collection can be controlled by program?

A. True
B. False
Answer» C.
1436.

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» D. GC parameter tuning
1437.

Which of the below is not a Java Profiler?

A. JVM
B. JConsole
C. JProfiler
D. Eclipse Profiler
Answer» B. JConsole
1438.

What happens to 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» D. The thread and garbage collection do not interfere with each other
1439.

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» B. memorymap
1440.

Which exception is thrown when java is out of memory?

A. MemoryFullException
B. MemoryOutOfBoundsException
C. OutOfMemoryError
D. MemoryError
Answer» D. MemoryError
1441.

What is -Xms and -Xmx while starting jvm?

A. Initial; Maximum memory
B. Maximum; Initial memory
C. Maximum memory
D. Initial memory
Answer» B. Maximum; Initial memory
1442.

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» C. Space management model
1443.

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» B. Old space
1444.

Which of the following has highest memory requirement?

A. Heap
B. Stack
C. JVM
D. Class
Answer» D. Class
1445.

What would be behaviour if constructor has a return type?

A. Compilation error
B. Runtime error
C. Compilation and runs successfully
D. Only String return type is allowed
Answer» B. Runtime error
1446.

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» E.
1447.

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» E.
1448.

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» C. Protected constructor can be used outside package
1449.

Abstract class cannot have a constructor.

A. True
B. False
Answer» C.
1450.

What is true about constructor?

A. It can contain return type
B. It can take any number of parameters
C. It can have any non access modifiers
D. Constructor cannot throw exception
Answer» C. It can have any non access modifiers