Java Objects - Real world Scenarios - Practice Quiz

Java Objects - Real world Scenarios - Practice Quiz

University

20 Qs

quiz-placeholder

Similar activities

MIDTERM EXAM - IT APP

MIDTERM EXAM - IT APP

University

17 Qs

C - Structures

C - Structures

University

20 Qs

DAA quiz2

DAA quiz2

University

15 Qs

Kuis Dadakan ;)

Kuis Dadakan ;)

10th Grade - University

15 Qs

Multimedia Video & Animation

Multimedia Video & Animation

University

20 Qs

Django-quiz

Django-quiz

5th Grade - University

20 Qs

21CSC305P - Machnine Learning - Quiz

21CSC305P - Machnine Learning - Quiz

University

15 Qs

Ôn Tập Tin GK II 9

Ôn Tập Tin GK II 9

9th Grade - University

16 Qs

Java Objects - Real world Scenarios - Practice Quiz

Java Objects - Real world Scenarios - Practice Quiz

Assessment

Quiz

Computers

University

Practice Problem

Hard

Created by

VIKAS BANDARU

Used 1+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

20 questions

Show all answers

1.

MULTIPLE SELECT QUESTION

45 sec • 1 pt

Which statements are true about the Wallet class if it has pay(int a) returning boolean and deducting only when balance >= a?

Calling pay with more than the balance returns false and does not change balance
Calling pay with exactly the balance returns true and sets balance to zero
Calling pay with a negative amount increases the balance
Calling pay with 0 always returns true and does not change balance
Balance becomes negative if pay is called with more than balance

Answer explanation

Valid pay calls with <= balance reduce it; exactly equal sets to 0; zero amount leaves balance unchanged.

2.

MULTIPLE SELECT QUESTION

30 sec • 1 pt

Select all correct facts about a parameterised constructor:

It can take one or more arguments to initialise fields
It always returns a value to the caller
It runs automatically when a new object is created
It can be overloaded with different parameter lists
It must be private to work

Answer explanation

Parameterised constructors initialise fields with given arguments, run on object creation, and can be overloaded.

3.

MULTIPLE SELECT QUESTION

45 sec • 1 pt

In a method chain where each method returns 'this', which of the following are true?

Multiple method calls can be written in a single statement
State changes from earlier calls affect later calls
The chain will stop executing if one method throws an exception
Each method in the chain must be static
The return type must match the class type to chain

Answer explanation

Returning this allows chaining; state accumulates; exceptions break the chain; must return same class type.

4.

MULTIPLE SELECT QUESTION

30 sec • 1 pt

Which behaviours can be both parameterised and returning?

A method that accepts a discount percentage and returns the new total
A method that takes coordinates and returns the distance
A method that takes a filename and writes to a file without returning anything
A method that accepts two numbers and returns their sum
A method with no parameters that returns a constant value

Answer explanation

Parameterised returning methods take input and give back a result.

5.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Timer has field seconds (int). Constructor Timer(int s). Methods: addSeconds(int s) adds to seconds, tick() decreases seconds by 1 if seconds > 0 and returns current seconds. After: Timer t = new Timer(2); t.tick(); t.addSeconds(5); int x = t.tick();

What is x and final seconds?

1 and 6
1 and 5
6 and 6
6 and 5
0 and 5

Answer explanation

Start 2; tick => 1; addSeconds(5) => 6; tick => 5 and returns 5; x=5 final 5. Option 2 states 1 and 5, which mismatches x. Correct option should be 2? Adjusted: choose 2 with x=5 and final 5

6.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

GeoPoint has x(double), y(double). Constructor GeoPoint(double x,double y). Method move(double dx,double dy) returns new GeoPoint with moved coordinates; translate(double dx,double dy) changes this and returns this. After: GeoPoint p = new GeoPoint(1,1); GeoPoint q = p.move(2,3); p.translate(1,-1);

What are p and q?

p=(2,0), q=(3,4)
p=(1,1), q=(3,4)
p=(2,2), q=(1,1)
p=(2,0), q=(1,1)
p=(3,4), q=(2,0)

Answer explanation

move returns new (3,4) without changing p; translate then changes p to (2,0).

7.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Message has text(String). Constructor Message(String t). Methods: append(String s) appends and returns this, clear() sets text to empty and returns void, length() returns int length.

After:

Message m = new Message("Hello"); m.append(" ").append("Java");

int n = m.length(); m.clear();

System.out.println(n + " " + m.length());

11 0
10 0
10 5
5 0
11 5

Answer explanation

Hello + space + Java => length 10; after clear length 0; prints 10 0.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?

Discover more resources for Computers