Java Programming
Java OOP, collections, multithreading
958 Questions 10 Topics Take Test
Advertisement
Showing 901–910 of 958 questions
Q.901 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.902 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.903 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.904 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.905 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
Advertisement
Q.906 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.907 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.908 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
Q.909 Hard Basics & Syntax
Which statement about Java's garbage collection is true?
A Garbage collection is deterministic and happens at fixed intervals
B Garbage collection is non-deterministic and may never run
C Calling System.gc() guarantees immediate garbage collection
D Objects are garbage collected as soon as they go out of scope
Correct Answer:  B. Garbage collection is non-deterministic and may never run
EXPLANATION

Garbage collection in Java is non-deterministic. System.gc() is just a request, not a guarantee. Objects are eligible for GC when unreachable, but actual collection timing varies.

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

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