Java Reference
In-Depth Information
a.
Write a statement to instantiate the object
myState
with the values
"Alaska"
,
626932
, and
586412.00
, respectively.
b.
Write a statement that outputs the value of the instance variable
name
of the object
myState
.
c.
Write a statement that changes the value of the instance variable
population
of the object
myState
to
627000
.
13.
Explain why we need both
public
and
private
members in a class?
14.
Write a Java statement that creates the object
mysteryClock
of the
Clock
type and initializes the instance variables
hr
,
min
,and
sec
of
mysteryClock
to
7
,
18
,and
39
, respectively.
15.
Given the statements:
Clock firstClock =
new
Clock(2, 6, 35);
Clock secondClock =
new
Clock(6, 23, 17);
firstClock = secondClock;
what is the output of the following statements?
firstClock.print();
System.out.println();
secondClock.print();
System.out.println();
16.
Consider the following declarations:
public class
XClass
{
private int
u;
private double
w;
public
XClass()
{
}
public
XClass(
int
a,
double
b)
{
}
public void
func()
{
}
public void
print()
{
}
}
XClass x =
new
XClass(10, 20.75);
a.
How many members does
class
XClass
have?
b.
How many
private
members does
class
XClass
have?
Search WWH ::
Custom Search