0%
0 / 12 answered
this Keyword Practice Test
•12 QuestionsQuestion
1 / 12
Q1
In the code snippet below, what problem does 'this' solve in the provided class definition?
class Rectangle {
private int length;
private int width;
public Rectangle(int length, int width) {
// 'this' distinguishes instance variables from parameters
this.length = length;
this.width = width;
}
public int area() {
// method call on the current object
return this.computeArea();
}
private int computeArea() {
return length * width;
}
}
In the code snippet below, what problem does 'this' solve in the provided class definition?
class Rectangle {
private int length;
private int width;
public Rectangle(int length, int width) {
// 'this' distinguishes instance variables from parameters
this.length = length;
this.width = width;
}
public int area() {
// method call on the current object
return this.computeArea();
}
private int computeArea() {
return length * width;
}
}