Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

476 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 451–460 of 476
Topics in Java Programming
Q.451 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.

Test
Q.452 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.

Test
Q.453 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

Test
Q.454 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.

Test
Q.455 Medium Basics & Syntax
Which access modifier allows access within the same package and subclasses?
A public
B private
C protected
D default
Correct Answer:  C. protected
EXPLANATION

protected allows access within the same package and to subclasses even outside the package.

Test
Q.456 Medium Basics & Syntax
What is the difference between == and .equals() for String comparison?
A Both check string content
B == checks reference, .equals() checks content
C == checks content, .equals() checks reference
D They are identical in functionality
Correct Answer:  B. == checks reference, .equals() checks content
EXPLANATION

== compares object references (memory location), while .equals() compares the actual string content.

Test
Q.457 Medium Basics & Syntax
Which statement about Java's 'this' keyword is correct?
A 'this' refers to the parent class
B 'this' refers to the current object instance
C 'this' is a static reference
D 'this' cannot be used in constructors
Correct Answer:  B. 'this' refers to the current object instance
EXPLANATION

'this' is a reference to the current object instance. It's used to distinguish instance variables from parameters and to call other constructors.

Test
Q.458 Medium Basics & Syntax
What is the output of: double d = 5.7; int i = (int) d; System.out.println(i);
A 6
B 5.7
C 5
D Error
Correct Answer:  C. 5
EXPLANATION

Explicit casting from double to int truncates the decimal part. 5.7 becomes 5 (not rounded).

Test
Q.459 Medium Basics & Syntax
What will be the output: int a = 10; int b = 20; System.out.println(a > b ? "A" : "B");
A A
B B
C Error
D AB
Correct Answer:  B. B
EXPLANATION

Ternary operator: condition ? trueValue : falseValue. Since 10 > 20 is false, "B" is printed.

Test
Q.460 Medium Basics & Syntax
Which of the following correctly initializes a 2D array in Java?
A int[][] arr = new int[3][4];
B int[] arr[] = new int[3][4];
C Both A and B
D Neither A nor B
Correct Answer:  C. Both A and B
EXPLANATION

Both syntaxes are valid in Java for declaring 2D arrays. The brackets can be placed after the type or variable name.

Test
IGET
IGET AI
Online · Exam prep assistant
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