public class Secret { private int x; private static int y; public static int cou
ID: 3803268 • Letter: P
Question
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 object’s 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
zero
one
two
three
Explanation / Answer
Question 7
How many constructors are present in the class definition in the accompanying figure?
Ans)Three
__________________
Question 8
Which of the following is a constructor without parameters?
Ans)default constructor
__________________
Question 9
In ____ copying, each reference variable refers to its own object.
Ans) deep
__________________
Question 10
Which of the following statements correctly instantiates the Rectangle object myRectangle?
Ans) Only (ii)
__________________
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?
Ans)public Book(Book b)
__________________
Question 12
What is the default definition of the method toString?
Ans) 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.
__________________
Question 13
What is the main use of inner classes?
Ans) To handle events
__________________
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.