Java Programming — Basics & Syntax
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 41–50 of 100 questions in Basics & Syntax
Q.41 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.42 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
Q.43 Medium Basics & Syntax
Which statement about method parameters is correct?
A Parameters are passed by reference in Java
B Parameters are passed by value in Java
C Objects are passed by reference, primitives by value
D All parameters are passed by reference
Correct Answer:  B. Parameters are passed by value in Java
EXPLANATION

Java uses pass-by-value for all parameters. For objects, the value passed is the reference, but the reference itself is passed by value.

Take Test
Q.44 Medium Basics & Syntax
What is the output of: System.out.println(true && false || true);
A true
B false
C null
D Compilation Error
Correct Answer:  A. true
EXPLANATION

Evaluation: (true && false) || true = false || true = true. AND operator (&& has higher precedence than OR (||).

Take Test
Q.45 Medium Basics & Syntax
Which of the following will result in a compilation error? class Test { public void method1() { } public void method1(int x) { } }
A Method overloading
B Method overriding
C No error, valid code
D Syntax error
Correct Answer:  C. No error, valid code
EXPLANATION

This is valid method overloading. Two methods with same name but different parameters (method signature) is allowed in Java.

Take Test
Q.46 Medium Basics & Syntax
What is the scope of a variable declared inside a method in Java?
A Global
B Local
C Static
D Package-level
Correct Answer:  B. Local
EXPLANATION

Variables declared inside a method have local scope and are only accessible within that method. They are destroyed when the method returns.

Take Test
Q.47 Easy Basics & Syntax
Which of the following is a valid method name in Java?
A 2ndMethod()
B _myMethod()
C my-method()
D my method()
Correct Answer:  B. _myMethod()
EXPLANATION

Method names must start with a letter, underscore, or dollar sign. '_myMethod()' is valid. Names cannot start with digits, contain hyphens, or spaces.

Take Test
Q.48 Easy Basics & Syntax
Consider the code: int x = 5; x += 3; What is the value of x?
A 5
B 8
C 3
D 53
Correct Answer:  B. 8
EXPLANATION

The compound assignment operator += means x = x + 3. So 5 + 3 = 8.

Take Test
Q.49 Easy Basics & Syntax
What will be the output of: System.out.println(10 / 3);
A 3.33
B 3
C 3.333333
D Compilation Error
Correct Answer:  B. 3
EXPLANATION

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.

Take Test
Q.50 Easy Basics & Syntax
What is the purpose of the 'instanceof' operator?
A To create new instances
B To check if an object is an instance of a class
C To compare object values
D To delete object instances
Correct Answer:  B. To check if an object is an instance of a class
EXPLANATION

The 'instanceof' operator is used to check if an object is an instance of a specific class or implements a specific interface.

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