Java Reference
In-Depth Information
c.
How many constructors does
class
XClass
have?
d.
Write the definition of the member
func
so that
u
is set to
10
and
w
is
set to
15.3
.
e.
Write the definition of the member
print
that prints the contents of
u
and
w
.
f.
Write the definition of the default constructor of the
class
XClass
so
that the instance variables are initialized to
0
.
g.
Write the definition of the constructor with parameters of the
class
XClass
so that the instance variable
u
is initialized to the value of
a
and
the instance variable
w
is initialized to the value of
b
.
h.
Write a Java statement that prints the values of the instance variables of
x
.
i.
Write a Java statement that creates the
XClass
object
t
and initializes
the instance variables of
t
to
20
and
35.0
, respectively.
17.
Explain shallow copying.
18.
Explain deep copying.
19.
Suppose that two reference variables, say
aa
and
bb
, of the same type point
to two different objects. What happens when you use the assignment
operator to copy the value of
aa
into
bb
?
20.
Assume that the method
toString
is defined for the
class
Clock
as given
in this chapter. What is the output of the following statements?
Clock firstClock;
Clock secondClock =
new
Clock(6, 23, 17);
8
firstClock = secondClock.getCopy();
System.out.println(firstClock);
21.
What is the purpose of the copy constructor?
22.
How does Java use the reference
this
?
23.
Can you use the relational operator
¼¼
to determine whether two different
objects of the same
class
type contain the same data?
24.
Consider the definition of the following
class
:
class
TestClass
{
private int
x;
private int
y;
//Default constructor to initialize
//the instance variables to 0
public
TestClass()
{
}
Search WWH ::
Custom Search