Sei sulla pagina 1di 4

Java II Tutorial 1

1. a. False
b. True
c. True
d. False
e. False
3. public int AA(int a, int b) => public void AA(int a, int b)
5. a) i. CC one = new CC(); = line 1
ii. CC two = new CC(5, 6); = line 3
iii. CC three = new CC(2, 8, 3.5); = line 4

b) public CC(){
u = 0;
w = 0;
v = 0;
}
c) public CC(int a){
u = a;
v = 0;
w = 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. A class can have more than one constructor. A constructor without parameters
is called the default constructor. Constructors automatically execute when a class
object is created.

11. a. c1 = new Clock();


It creates the object c1, and the instance variables hr, min,
and sec are initialized to 0.

b. c2 = new Clock(5, 12, 30);


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. c1.setTime(3, 24, 36);


The values of the instances hr, min, and sec of the object c1 are set to 3, 24,
and 36, respectively.
d. c2.setHours(9);
The value of the instance variables hr of the object c2 is set to 9.
13. In a UML class diagram, the top box contains the name of the class. The
middle box contains the data members and their data types. The bottom box
contains the methods’ names, parameter list, and return type. A + (plus) sign in
front of a member indicates that the member is a public member; a - (minus) sign
indicates that this is a private member. The # symbol before a member name
indicates that the member is a protected member.

15. firstClock.print();
System.out.println();
secondClock.print();
System.out.println();
No output cuz don’t have method in the statement.

17. A shallow copy is a copy of the reference pointer to the object, where as
a deep copy is a copy of the object itself. In Java, objects are kept in the
background, what you normally interact with when dealing with the objects is the
pointers. The variable names point to the memory space of the object.

19. When I use the assignment operator to copy the value of aa into bb. Then
both value of aa and bb are same.

21. Copy constructor is used to create copies of an object.


23. import java.util.*;
public class test
{
public static void main(String[] args)
{
int n = 0;
int n2 = 0;

if(n == n2)
System.out.println();

}
}

Potrebbero piacerti anche