Java Objects - Medium Practice Quiz

Java Objects - Medium Practice Quiz

12th Grade

20 Qs

quiz-placeholder

Similar activities

Code.org: AP CSA U3, Lessons 1-6 Review

Code.org: AP CSA U3, Lessons 1-6 Review

11th - 12th Grade

20 Qs

Java Base

Java Base

9th - 12th Grade

19 Qs

AP Computer Science A Unit 1

AP Computer Science A Unit 1

9th - 12th Grade

19 Qs

OOP - Java Classes

OOP - Java Classes

12th Grade - University

15 Qs

Java Basics

Java Basics

12th Grade

17 Qs

Arrays in Java

Arrays in Java

9th - 12th Grade

20 Qs

Arrays

Arrays

9th - 12th Grade

16 Qs

JAVA FUNDAMENTALS

JAVA FUNDAMENTALS

9th - 12th Grade

20 Qs

Java Objects - Medium Practice Quiz

Java Objects - Medium Practice Quiz

Assessment

Quiz

Computers

12th Grade

Medium

Created by

VIKAS BANDARU

Used 1+ times

FREE Resource

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which statement best describes a parameterised constructor in OOP?
A method that returns a value to the caller
A special method that sets initial field values using arguments during object creation
A static initializer that runs once per class
Any method that accepts parameters
A method that only draws on screen

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?
456789
123
3456789
56789
1234

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?
345678
34567
45678
34
567

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?

3 and 0
0 and 0
0 and 3
-1 and 0
3 and 3

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?
void makeVisible()
int moveHorizontal()
int moveHorizontal(int distance)
void changeColor(String color)
void moveDown()

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?
0
150
50
200
100

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?
moveRight()
moveDown()
moveHorizontal(int distance)
makeVisible()
draw()

Answer explanation

moveHorizontal changes xPosition using the distance provided by the caller.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?