Java Objects - Real world Scenarios - Practice Quiz
Quiz
•
Computers
•
University
•
Practice Problem
•
Hard
VIKAS BANDARU
Used 1+ times
FREE Resource
Enhance your content in a minute
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?
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:
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?
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?
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?
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?
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());
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

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
16 questions
Think it through
Quiz
•
University - Professi...
15 questions
Fundamentals of Algorithms - Unit 1 - Test 1
Quiz
•
University
20 questions
POO_BasicoyJava
Quiz
•
University
20 questions
Control Structures C#
Quiz
•
University
15 questions
BASIC C QUIZ
Quiz
•
University
15 questions
Object Oriented Programming Assessment 1
Quiz
•
University
19 questions
Programación Básica Prácticas Tema 2
Quiz
•
University
16 questions
Subprograms and ADT
Quiz
•
University
Popular Resources on Wayground
5 questions
This is not a...winter edition (Drawing game)
Quiz
•
1st - 5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
10 questions
Identify Iconic Christmas Movie Scenes
Interactive video
•
6th - 10th Grade
20 questions
Christmas Trivia
Quiz
•
6th - 8th Grade
18 questions
Kids Christmas Trivia
Quiz
•
KG - 5th Grade
11 questions
How well do you know your Christmas Characters?
Lesson
•
3rd Grade
14 questions
Christmas Trivia
Quiz
•
5th Grade
20 questions
How the Grinch Stole Christmas
Quiz
•
5th Grade
Discover more resources for Computers
26 questions
Christmas Movie Trivia
Lesson
•
8th Grade - Professio...
20 questions
christmas songs
Quiz
•
KG - University
20 questions
Holiday Trivia
Quiz
•
9th Grade - University
15 questions
Holiday Movies
Quiz
•
University
14 questions
Christmas Trivia
Quiz
•
3rd Grade - University
20 questions
Christmas Trivia
Quiz
•
University
8 questions
5th, Unit 4, Lesson 8
Lesson
•
KG - Professional Dev...
20 questions
Disney Trivia
Quiz
•
University
