
Java Objects - Medium Practice Quiz
Authored by VIKAS BANDARU
Computers
12th Grade
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 CHOICE QUESTION
30 sec • 1 pt
Which statement best describes a parameterised constructor in OOP?
Answer explanation
A parameterised constructor takes arguments and assigns initial values to fields when an object is created.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Given: String s = "0123456789"; System.out.println(s.substring(4)); What is printed?
Answer explanation
substring(4) returns characters from index 4 to end, yielding 456789.
3.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Given: String s = "0123456789"; System.out.println(s.substring(s.lastIndexOf('3'), s.indexOf('8'))); What is printed?
Answer explanation
lastIndexOf('3') is 3, indexOf('8') is 8; substring(3,8) gives 34567.
4.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Given:
String s = "abcabc";
System.out.println(s.lastIndexOf("abc", 2));
System.out.println(s.substring(3, 3).length());
What is printed on two lines?
Answer explanation
lastIndexOf("abc", 2) searches up to index 2 inclusive, finds abc at 0; substring(3,3) is empty, length is 0.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which option correctly identifies a parameterised method that also returns a value?
Answer explanation
moveHorizontal(int distance) both takes a parameter and could be defined to return an int; among given options, it matches signature of parameterised and returning method.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider class Account { int balance; Account(int initial){ balance = initial + 50; } } After Account a = new Account(150); what is a.balance?
Answer explanation
The parameterised constructor sets balance = initial + 50, so 150 + 50 = 200.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
In Circle, which method changes position based on caller-provided information?
Answer explanation
moveHorizontal changes xPosition using the distance provided by the caller.
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?