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
20 questions
Week 5: Test your understanding part 1
Quiz
•
University
15 questions
Data Mining - Classification Mining
Quiz
•
University
15 questions
python basics
Quiz
•
11th Grade - University
15 questions
Шаблоны проектирования
Quiz
•
University
20 questions
DATASET'24 Quizz (Round 1)
Quiz
•
University
20 questions
Web Development and Programming
Quiz
•
University
16 questions
Quiz on List and Tuples
Quiz
•
University
15 questions
OS Quiz-1
Quiz
•
University
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
