
Java Objects - Real world Scenarios - Practice Quiz
Authored by VIKAS BANDARU
Computers
University
Used 1+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
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
17 questions
Introduction to Computer Systems: Basic elements
Quiz
•
University - Professi...
15 questions
Web Dev Midterm Quiz
Quiz
•
University
15 questions
cmd and terminal
Quiz
•
7th Grade - University
17 questions
Minggu V - PKS 2 - Pemrograman C++
Quiz
•
University
16 questions
Algo Quiz
Quiz
•
University
20 questions
Data & Signal
Quiz
•
University
18 questions
Quiz on Misinformation and Bias
Quiz
•
10th Grade - University
20 questions
COA_QUIZ_UNIT I
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
29 questions
Alg. 1 Section 5.1 Coordinate Plane
Quiz
•
9th Grade
22 questions
fractions
Quiz
•
3rd Grade
11 questions
FOREST Effective communication
Lesson
•
KG
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
Discover more resources for Computers
12 questions
IREAD Week 4 - Review
Quiz
•
3rd Grade - University
7 questions
Fragments, Run-ons, and Complete Sentences
Interactive video
•
4th Grade - University
7 questions
Renewable and Nonrenewable Resources
Interactive video
•
4th Grade - University
10 questions
DNA Structure and Replication: Crash Course Biology
Interactive video
•
11th Grade - University
5 questions
Inherited and Acquired Traits of Animals
Interactive video
•
4th Grade - University
5 questions
Examining Theme
Interactive video
•
4th Grade - University
20 questions
Implicit vs. Explicit
Quiz
•
6th Grade - University
7 questions
Comparing Fractions
Interactive video
•
1st Grade - University