Java Reference
In-Depth Information
5.
a.
i. Constructor at Line 1.
ii. Constructor at Line 3.
iii. Constructor at Line 4.
b.
public
CC()
{
u = 0;
v = 0;
w = 0.0;
}
c.
public
CC(
int
a)
{
u = a;
v = 0;
w = 0.0;
}
d.
public
CC(
int
a,
int
b)
{
u = a;
v = b;
w = 0.0;
}
e.
public
CC(
int
a,
int
b,
double
d)
{
u = a;
v = b;
w = d;
}
7.
Automobile
9. One.
11.
a. It creates the object
c1
, and the instance variables
hr
,
min
,and
sec
are initialized to
0
.
b. It creates the object
c2
. The instance variable
hr
is initialized to
5
, the instance
variable
min
is initialized to
12
, and the instance variable
sec
is initialized to
30
.
c. The values of the instance variables
hr
,
min
, and
sec
of the object
c1
are set to
3
,
24
, and
36
, respectively.
d. The value of the instance variables
hr
of the object
c2
is set to
9
.
13.
In Java, a class combines data and operations on data in a single unit. Typically, we do
not want the user to directly manipulate the data, so data members are declared as
private
. To allow the users to manipulate the
private
members of a class, the
user is provided with
public
members. Therefore, we need both
public
and
private
members in a class.
Search WWH ::
Custom Search