public void Coin( )
{
flip( );
}
Ans: A constructor cannot be declared with the return value void
or any other return value.
> javac Coin.java > java Coin.javaAns: (1) The second line should be java Coin. (2) The Coin class does not contain a main method, so java Coin will not work. The calls should be:
> javac Coin.java TestCoin.java > java Coin
public void flip( )
{
if (Math.random( ) >= 0.5)
headsUp = true;
else
headsUp = false;
}
Ans:
public void flip( )
{
headsUp = Math.random( ) >= 0.5;
}
Person p = new Person("Alice", 'F', 23);
Person q = new Person("Shawn", 'M', 19);
q = p;
Ans: The variable p contains an arrow that points to the object
with instance variables Alice, F, 23. The variable q contains an arrow
that points to the object with instance variables Shawn, M, 19. When
the statement q = p is executed, the arrow for q that points to
the object Shawn is changed to point to the object Alice.
Ans:
public static void main(String[ ]) q = p;
sum = 0;
for(i = 1, i != 100, i += 2);
sum + = i;
int sec = theSec;
if (sec == 60);
{
sec = 0;
min++;
}
double[ ] x;
x = new double[50];
x[31] = 452.376;
v = x[31];
{ 67, 23, 57, 93, 91, 45, 29 }
if (a[0] > a[1])
{
temp = a[0];
a[0] = a[1];
a[1] = temp;
}
if (a[1] > a[2])
{
temp = a[1];
a[1] = a[2];
a[2] = temp;
}
if (a[0] > a[1])
{
temp = a[0];
a[0] = a[1];
a[1] = temp;
}
| i | j | a[0] | a[1] | a[2] | a[3] | a[4] | temp |
|---|---|---|---|---|---|---|---|
| 45 | 34 | 76 | 53 | 40 | |||
Add more rows in the table as needed.