Home Subjects Java Programming Basics & Syntax

Java Programming
Basics & Syntax

Java OOP, collections, multithreading

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 51–60 of 100
Topics in Java Programming
Q.51 Hard Basics & Syntax
Which statement about Java's garbage collection is true?
A Garbage collection is deterministic and happens at fixed intervals
B Garbage collection is non-deterministic and may never run
C Calling System.gc() guarantees immediate garbage collection
D Objects are garbage collected as soon as they go out of scope
Correct Answer:  B. Garbage collection is non-deterministic and may never run
EXPLANATION

Garbage collection in Java is non-deterministic. System.gc() is just a request, not a guarantee. Objects are eligible for GC when unreachable, but actual collection timing varies.

Take Test
Q.52 Medium Basics & Syntax
Consider: class A { static int x = 5; } How many times is x initialized when you create multiple A objects?
A Once per object creation
B Once when the class is loaded
C Multiple times depending on object count
D Twice (once for class, once for object)
Correct Answer:  B. Once when the class is loaded
EXPLANATION

Static variables are initialized only once when the class is first loaded into memory, regardless of object creation.

Take Test
Q.53 Easy Basics & Syntax
What does the 'super' keyword do in Java?
A Refers to the current object
B Refers to the parent class
C Creates a new instance
D Marks a method as superior
Correct Answer:  B. Refers to the parent class
EXPLANATION

The 'super' keyword is used to refer to parent class members and invoke parent class constructors.

Take Test
Q.54 Medium Basics & Syntax
Which of the following cannot be inherited in Java?
A Public methods
B Protected methods
C Private methods
D Static methods can be inherited
Correct Answer:  C. Private methods
EXPLANATION

Private members are not inherited. They remain accessible only within the class they are declared in.

Take Test
Q.55 Hard Basics & Syntax
What is the result of: int x = 5; System.out.println(x++ + ++x);?
A 10
B 11
C 12
D 13
Correct Answer:  B. 11
EXPLANATION

x++ returns 5 (then increments to 6), ++x increments to 7 and returns 7. Sum = 5+7 = 12. Note: Actual result may vary due to JVM optimization but typically 11 or 12.

Take Test
Q.56 Medium Basics & Syntax
Which of the following about static variables is incorrect?
A Static variables are shared among all instances
B Static variables are initialized when class loads
C Each object has its own copy of static variables
D Static variables can be accessed using class name
Correct Answer:  C. Each object has its own copy of static variables
EXPLANATION

Static variables are shared among ALL instances of a class, not individual copies per object.

Take Test
Q.57 Medium Basics & Syntax
What is the output of: System.out.println(5 % 2 + 3 * 2 - 1);?
A 6
B 7
C 8
D 10
Correct Answer:  A. 6
EXPLANATION

Following operator precedence: 5%2=1, 3*2=6, then 1+6-1=6

Take Test
Q.58 Easy Basics & Syntax
Which of the following is a valid variable declaration?
A int 2num;
B int num-2;
C int num$2;
D int num.2;
Correct Answer:  C. int num$2;
EXPLANATION

Variable names can contain letters, digits, underscores, and dollar signs, but cannot start with a digit or contain hyphens or dots.

Take Test
Q.59 Medium Basics & Syntax
Which statement about constructor overloading is true?
A Constructors cannot be overloaded
B Constructors can be overloaded with different parameter types and counts
C Only one constructor is allowed per class
D Constructor return type must differ for overloading
Correct Answer:  B. Constructors can be overloaded with different parameter types and counts
EXPLANATION

Constructors can be overloaded based on parameter count and types, but not on return type.

Take Test
Q.60 Easy Basics & Syntax
What is the correct way to declare a constant in Java?
A const int MAX = 100;
B static int MAX = 100;
C public static final int MAX = 100;
D final static int MAX = 100;
Correct Answer:  C. public static final int MAX = 100;
EXPLANATION

'const' is not a Java keyword. The correct convention for constants is public static final. Option D also works but C follows the standard convention.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips