Java Reference
In-Depth Information
9.32
✓
✓
Describe the role of the
this
keyword.
Check
9.33
Point
What is wrong in the following code?
1
public class
C {
2
private int
p;
3
4
public
C() {
5 System.out.println(
"C's no-arg constructor invoked"
);
6
this
(
0
);
7 }
8
9
public
C(
int
p) {
10 p = p;
11 }
12
13
public void
setP(
int
p) {
14 p = p;
15 }
16 }
9.34
What is wrong in the following code?
public class
Test {
private int
id;
public void
m1() {
this
.id =
45
;
}
public void
m2() {
Test.id =
45
;
}
}
K
EY
T
ERMS
action 322
anonymous object
immutable object
353
331
no-arg constructor
329
attribute
322
null
value
331
behavior
322
object 322
object-oriented programming (OOP)
class 322
class's variable
322
355
package-private (or package-access)
342
client 325
constructor 322
data field 322
data field encapsulation
private constructor
344
property 322
public class 325
reference type 330
reference variable
344
default constructor 329
dot operator (
.
) 330
getter (or accessor)
330
setter (or mutator)
345
345
state 322
static method 337
static variable 337
this
keyword 356
Unified Modeling Language (UML)
instance 322
instance method
331
instance variable
331
instantiation 322
immutable class
323
353
Search WWH ::
Custom Search