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 61–70 of 100
Topics in Java Programming
Q.61 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.

Take Test
Q.62 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.

Take Test
Q.63 Easy Basics & Syntax
Which of the following statements about Java packages is correct?
A Package names must be in uppercase
B Package names use dot notation for hierarchy
C A single Java file can belong to multiple packages
D Package statement must appear after import statements
Correct Answer:  B. Package names use dot notation for hierarchy
EXPLANATION

Package names follow a hierarchical structure using dots (e.g., com.example.app). Package statement must be the first non-comment statement.

Take Test
Q.64 Easy Basics & Syntax
Which keyword is used to prevent method overriding in Java?
A abstract
B final
C static
D synchronized
Correct Answer:  B. final
EXPLANATION

The 'final' keyword prevents a method from being overridden by subclasses.

Take Test
Q.65 Easy Basics & Syntax
Which of the following is NOT a valid Java identifier?
A _variable123
B $myVar
C 123variable
D my_Var$
Correct Answer:  C. 123variable
EXPLANATION

Java identifiers cannot start with a digit. Valid identifiers must start with a letter, underscore, or dollar sign.

Take Test
Q.66 Easy Basics & Syntax
What will be the output of: System.out.println(Math.max(5, 10) - Math.min(3, 8));
A 2
B 5
C 7
D 15
Correct Answer:  C. 7
EXPLANATION

Math.max(5, 10) = 10, Math.min(3, 8) = 3. So 10 - 3 = 7.

Take Test
Q.67 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.

Take Test
Q.68 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).

Take Test
Q.69 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.

Take Test
Q.70 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.

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