Java Programming
Java OOP, collections, multithreading
958 Questions 10 Topics Take Test
Advertisement
Showing 891–900 of 958 questions
Q.891 Medium Basics & Syntax
What is the purpose of the 'this' keyword in Java?
A To refer to the parent class
B To refer to the current object instance
C To create a new object
D To access static variables
Correct Answer:  B. To refer to the current object instance
EXPLANATION

'this' is a reference variable that refers to the current object instance. It is used to distinguish instance variables from local variables with the same name, or to pass the current object as a parameter.

Take Test
Q.892 Easy Basics & Syntax
What will be the result of: int a = 10; int b = 20; System.out.println(a + b + "Java");?
A "30Java"
B "1020Java"
C "Java30"
D Compilation error
Correct Answer:  A. "30Java"
EXPLANATION

When + operator is used with numeric values first, they are added (10 + 20 = 30), and then concatenated with the string "Java", resulting in "30Java".

Take Test
Q.893 Easy Basics & Syntax
Which keyword is used to create a constant variable in Java that cannot be modified after initialization?
A static
B const
C final
D immutable
Correct Answer:  C. final
EXPLANATION

The 'final' keyword is used to declare constants in Java. Once a final variable is assigned a value, it cannot be changed. 'const' is a reserved keyword but not used in Java.

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

x++ uses current value (5) then increments, ++x increments first then uses value (7). Order of evaluation: 5 + 7 = 12. However, x becomes 7 after ++x.

Take Test
Q.895 Hard Basics & Syntax
Consider: class Parent { Parent() { System.out.println("P"); } } class Child extends Parent { Child() { System.out.println("C"); } } public static void main(String[] args) { new Child(); }
A C
B P
C P C
D C P
Correct Answer:  C. P C
EXPLANATION

Child constructor implicitly calls super() first, executing Parent constructor. Output: Parent prints 'P', then Child prints 'C'.

Take Test
Advertisement
Q.896 Hard Basics & Syntax
Which of the following will throw a NullPointerException? String s = null; System.out.println(s.length());
A s = null
B System.out
C s.length()
D println()
Correct Answer:  C. s.length()
EXPLANATION

Calling a method on a null reference throws NullPointerException. s.length() tries to invoke method on null, causing the exception.

Take Test
Q.897 Hard Basics & Syntax
What will be the output? class Test { public static void main(String[] args) { int x = 10; { int x = 20; System.out.println(x); } System.out.println(x); } }
A 10 20
B 20 10
C 20 20
D Compilation Error
Correct Answer:  B. 20 10
EXPLANATION

A block scope creates a new variable x = 20 which shadows the outer x. First print outputs 20, then the block ends, outer x (10) is printed.

Take Test
Q.898 Medium Basics & Syntax
Which of the following is a feature of Java 8 that allows functional programming?
A Lambda expressions
B Generics
C Annotations
D Enums
Correct Answer:  A. Lambda expressions
EXPLANATION

Lambda expressions were introduced in Java 8, enabling functional programming. Syntax: (parameters) -> expression or statement

Take Test
Q.899 Medium Basics & Syntax
Consider: String s1 = "Java"; String s2 = new String("Java"); System.out.println(s1 == s2);
A true
B false
C Compilation Error
D Runtime Error
Correct Answer:  B. false
EXPLANATION

s1 is created in string pool, s2 is a new object in heap. Though content is same, references are different, so == returns false.

Take Test
Q.900 Medium Basics & Syntax
What is the difference between == and equals() in Java?
A Both are identical
B == compares values, equals() compares references
C == compares references, equals() compares values
D equals() is only for objects, == is for primitives
Correct Answer:  C. == compares references, equals() compares values
EXPLANATION

== compares object references (memory addresses). equals() method compares actual content/values and can be overridden.

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