Hello and thank you for your support!
i'd like to discuss about this question, that i don't understand fully (although i've answered right.. ).
the question is:
A JavaBean has a property named size, which is accessible to and modifiable by all other classes. Which of the following statements are correct regarding this class?
one of the wrong answer was:
the class must have an instance variable named size.
and the explanation given is:
While quite intuitive and common, this is not a necessity. The getter and setter methods may have some computational logic that does not involve any instances variable or may involve multiple instance variables. If a JavaBean has a getX and setX method, it is said to have a property x, irrespective of whether it has an instance variable x or not.
i don't understand... shouldn't there be a variable named size to have the setter and getter setSize and getSize?
otherwise the setter and getter would get different names, i guess... so kindly, can you help me?
best regards
About Question com.enthuware.scja.v1.2.11 :
-
- Posts: 15
- Joined: Fri Jul 12, 2013 12:34 pm
- Contact:
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.scja.v1.2.11 :
Yes, for example, class Shape could have a getArea method but no area field because it is computed on the fly. So 'area' would still be a valid property (although read only, in this case) from JavaBeans perspective.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 15
- Joined: Fri Jul 12, 2013 12:34 pm
- Contact:
Re: About Question com.enthuware.scja.v1.2.11 :
Hi Paul,
thank you for your reply, but still, i've not understood, can you make me a practical example?
by the way... i wanted to thank all the staff in enthuware, i've passed the exam, and your software has been helpful!
thank you for your reply, but still, i've not understood, can you make me a practical example?
by the way... i wanted to thank all the staff in enthuware, i've passed the exam, and your software has been helpful!
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.scja.v1.2.11 :
The one I gave is a practical example:
HTH,
Paul.
Code: Select all
class Shape{
abstract double getArea();
}
class Square extends Shape{
private int side;
public int getArea(){ return side*side; }
}
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 2 guests