Java OOP GUIDE / WORK RECTANGLE CLASS 3
SOLUTIONS TASK –
PART 1 – SETUP No solution
required. TASK –
PART 2 – SHORT QUESTIONS a)
The class has 4 instance variables (x, y, width
and height) b)
It has 1 constructor. c)
It has 1 instance method (area). d)
In the top line of the constructor (header), you
will notice that two of the parameters have names that are identical as the instance
variables (x and y). So, in the constructor,
in order to access the instance variable x and y, we need to include the word
this in front of them. Since w
and h are different than the instance variable names width and height, there
is no issue for those variables and this is not needed. |
||
TASK –
PART 3 – DATA ENCAPSULATION Solution:
|