-
Notifications
You must be signed in to change notification settings - Fork 6
/
Module 6 quiz on methods and classes
78 lines (46 loc) · 1.6 KB
/
Module 6 quiz on methods and classes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Module 6 quiz on methods and classes
1. Making instance variables of a class private
****************************
Ans:-
is an application of abstraction and protects against object users gaining direct access to object state.
*********************************
2. A class method such as addMonthlyBonus(double x) that receives an input parameter and uses it to change the instance variable of an object is called a
*****************
Ans:-
mutator method
*******************
3. Select all of the following method definitions below that
employ the correct syntax to define a constructor for the class Vehicle. A partial list of the class instance variables includes:
int year;
double odometer;
...
********************************
Ans:-
public Vehicle(){
}
public Vehicle(double mileage, int year){
this(mileage);
this.year = year;
}
***********************************
4. When a constructor is written for the class (select all that apply)
***************************
Ans:-
the default constructor must be recreated if it is to be used by client programs.
**********************
5. When calling one constructor from another constructor
**********************
Ans:-
the keyword this is used and must be the first line of the constructor code.
********************************
6. Consider these two methods which are part of the Student class. Assume that age is a private instance variable of the class.
public void setAge(int years, int months){
age = years * 12 + months;
}
public void setAge(int months){
age = months;
}
********************
Ans:- mutators
overloading
**********************