Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

476 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 441–450 of 476
Topics in Java Programming
Q.441 Medium Basics & Syntax
Which of the following correctly demonstrates method overloading?
A Two methods with same name and same parameters in different classes
B Two methods with same name but different number or type of parameters in the same class
C Two methods with different names and different parameters in the same class
D Two methods with same name and return type in the same class
Correct Answer:  B. Two methods with same name but different number or type of parameters in the same class
EXPLANATION

Method overloading allows multiple methods with the same name but different parameters (number, type, or order) in the same class. This is a way to implement compile-time (static) polymorphism.

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

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

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

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

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

Test
Q.447 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 (||).

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

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

Test
Q.450 Medium Basics & Syntax
Consider: class A { static int x = 5; } How many times is x initialized when you create multiple A objects?
A Once per object creation
B Once when the class is loaded
C Multiple times depending on object count
D Twice (once for class, once for object)
Correct Answer:  B. Once when the class is loaded
EXPLANATION

Static variables are initialized only once when the class is first loaded into memory, regardless of object creation.

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