What is the correct way to declare a constant in Java?
Answer: C
'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.
Q.42Medium
Which statement about constructor overloading is true?
Answer: B
Constructors can be overloaded based on parameter count and types, but not on return type.
Q.43Easy
Which of the following is a valid variable declaration?
Answer: C
Variable names can contain letters, digits, underscores, and dollar signs, but cannot start with a digit or contain hyphens or dots.
Q.44Medium
What is the output of: System.out.println(5 % 2 + 3 * 2 - 1);?
Answer: A
Following operator precedence: 5%2=1, 3*2=6, then 1+6-1=6
Q.45Medium
Which of the following about static variables is incorrect?
Answer: C
Static variables are shared among ALL instances of a class, not individual copies per object.
Advertisement
Q.46Hard
What is the result of: int x = 5; System.out.println(x++ + ++x);?
Answer: B
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.
Q.47Medium
Which of the following cannot be inherited in Java?
Answer: C
Private members are not inherited. They remain accessible only within the class they are declared in.
Q.48Easy
What does the 'super' keyword do in Java?
Answer: B
The 'super' keyword is used to refer to parent class members and invoke parent class constructors.
Q.49Medium
Consider: class A { static int x = 5; } How many times is x initialized when you create multiple A objects?
Answer: B
Static variables are initialized only once when the class is first loaded into memory, regardless of object creation.
Q.50Hard
Which statement about Java's garbage collection is true?
Answer: B
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.
Q.51Easy
What is the purpose of the 'instanceof' operator?
Answer: B
The 'instanceof' operator is used to check if an object is an instance of a specific class or implements a specific interface.
Q.52Easy
What will be the output of: System.out.println(310);
Answer: B
Both operands are integers, so integer division is performed. Result is 3 (not 3.33). To get decimal, at least one operand must be float/double.
Q.53Easy
Consider the code: int x = 5; x += 3; What is the value of x?
Answer: B
The compound assignment operator += means x = x + 3. So 5 + 3 = 8.
Q.54Easy
Which of the following is a valid method name in Java?
Answer: B
Method names must start with a letter, underscore, or dollar sign. '_myMethod()' is valid. Names cannot start with digits, contain hyphens, or spaces.
Q.55Medium
What is the scope of a variable declared inside a method in Java?
Answer: B
Variables declared inside a method have local scope and are only accessible within that method. They are destroyed when the method returns.
Q.56Medium
Which of the following will result in a compilation error? class Test { public void method1() { } public void method1(int x) { } }
Answer: C
This is valid method overloading. Two methods with same name but different parameters (method signature) is allowed in Java.
Q.57Medium
What is the output of: System.out.println(true && false || true);
Answer: A
Evaluation: (true && false) || true = false || true = true. AND operator (&& has higher precedence than OR (||).
Q.58Medium
Which statement about method parameters is correct?
Answer: B
Java uses pass-by-value for all parameters. For objects, the value passed is the reference, but the reference itself is passed by value.
Q.59Medium
What is the difference between == and equals() in Java?
Answer: C
== compares object references (memory addresses). equals() method compares actual content/values and can be overridden.