Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: This question deals with the object constructor. You are given the following class Rock that has two constructors (overloaded). They both update the class

JAVA:

This question deals with the object constructor. You are given the following class Rock that has two constructors (overloaded). They both update the class variable (count) whenever an object is created.

class Rock {

static int count=0;

Rock() { // This is the constructor

System.out.print("Rock ");

count++;

}

Rock(int i) {

System.out.print("Rock " + i + " ");

this();

count++;

}

}

write a client program to display the following; rnum is between 0 to 10. rnum = 3 if it (random number) is <=3. You are only allowed to use the constructors (in the Rock Class) to display the Rock objects created.

For example:

rnum = 7

Rock Rock0 Rock Rock1 Rock Rock2 Rock Rock3 Rock Rock4 Rock Rock5 Rock Rock6

number of Rock objects created = 14

rnum = 1

Rock Rock0 Rock Rock1 Rock Rock2

number of Rock objects created = 6

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions