Nil. Hatamova wrote: Correct answer is e. But not code here. What is the correct code?
Nil. Hatamova wrote:
Is it enough or i must change the methods to private?
Nil. Hatamova wrote:I think encapsulation is protect variables from using outside. Other class cant change the variables*.
Nil. Hatamova wrote:Is it enough or i must change the methods to private?
Ramya Subraamanian wrote:I have a doubt in this ..the instance variable "model" is not accessed through getters / setters, so can it remain public and the class is still encapsulated ?
Ramya Subraamanian wrote:And if we set all the variables , their getters and setters private is it called tight encapsulation ?
Nil. Hatamova wrote:If i change method to private i cant call method in other class.
Nil. Hatamova wrote:Is it also encapsulation?
Ramya Subraamanian wrote:okay, even if there were no getters/setters the public instance variable "model" could still be accessed and modified. so it is important to make it private for the class to be completely encapsulated.
Ramya Subraamanian wrote:So the terms Encapsulated/Well-encapsulated/Tightly encapsulated ..all mean the same? There's no term as "tight encapsulation" in my OOAD(Grady booch) book
![]()
Yes! But you should also provide methods to access and/or change it. Because in your current Phone class the instance variable model is pretty useless as it can be accessed or retrieved.
Ramya Subraamanian wrote:Okay, thats right. But, what if I have specific requirement that I dont want anyother class to access/modify my "model" variable. So I dont want to create any public mutator/accessor methods. So now would the class still be called encapsulated.
Ramya Subraamanian wrote:Having said that...I dont want to assume anything
In exam perspective do you think this class is encapsulated or not..
Ramya Subraamanian wrote:String is immutable, but in the TestSpecial class even if you use a (return new StringBuilder(s)); it would still work right, it just returns bob without fred being appended. But I think I am missing an important scenario, where it could be modified.
Ramya Subraamanian wrote:And when encapsulating Arrays can we use Arrays.copyOf , which will create a valid copy of the array without exposing the original array?
Ramya Subraamanian wrote:there is is a stray 'a' in the printName() of OP's initial post, I think that is 's'. there is a 'x' in your add() method, I think it must be 'p'.
He's giving us the slip! Quick! Grab this tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|