Question: public class Secret { private int x; private static int y; public static int count; public int z; public Secret() { x = 0; z

public class Secret { private int x; private static int y; public static int count; public int z; public Secret() { x = 0; z = 1; } public Secret(int a) { x = a; } public Secret(int a, int b) { x = a; y = b; } public String toString() { return ("x = " + x + ", y = " + y + ", count = " + count); } public static void incrementY() { y++; } } How many constructors are present in the class definition in the accompanying figure?

zero

one

two

three

1 points

Question 8

Which of the following is a constructor without parameters?

copy constructor

default constructor

finalizer

modifier

1 points

Question 9

In ____ copying, each reference variable refers to its own object.

shallow

deep

method

object

1 points

Question 10

Consider the following class definition. public class Rectangle { private double length; private double width; public Rectangle() { length = 0; width = 0; } public Rectangle(double l, double w) { length = l; width = w; } public void set(double l, double w) { length = l; width = w; } public void print() { System.out.println(length + " " + width); } public double area() { return length * width; } public double perimeter() { return 2 * length + 2 * width; } } Which of the following statements correctly instantiates the Rectangle object myRectangle? (i) myRectangle = new Rectangle(12.5, 6); (ii) Rectangle myRectangle = new Rectangle(12.5, 6); (iii) class Rectangle myRectangle = new Rectangle(12.5, 6);

Only (i)

Only (ii)

Only (iii)

Both (ii) and (iii)

1 points

Question 11

Suppose that Book is class with two instance variables-name of type String and numOfBooks of type int. Which of the following would be appropriate syntax for the heading of a copy constructor for the class called Book?

public Book(String n, int num)

public Book()

public Book(Book b)

public copyBook(String n, int num)

1 points

Question 12

What is the default definition of the method toString?

There is no default definition; you must define the method yourself.

It creates a string that is the name of the objects class, followed by the hash code of the object.

It creates a string that is the name of the program.

It creates a string that is the name of the package, followed by the name of the class, followed by the hash of the object.

1 points

Question 13

What is the main use of inner classes?

To alter the behavior of the outer class

To handle events

To implement cascaded method calls

To provide information hiding

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!