Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla wrote:The array in your example is not public.
And this- 4. Methods in ClassA use public variables in ClassB - is the reason why C is true. For something to be public- it has to be declared as public.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
10.7 Array Members
The members of an array type are all of the following:
* The public final field length, which contains the number of components of the array (length may be positive or zero)
* The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions
* All the members inherited from class Object; the only method of Object that is not inherited is its clone method
Prepare for 'OCA Java SE 8 certification' with eJavaGuru.com
Author of Manning's OCA Java SE 8 bookProgrammer I Certification Guide, OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
Thanks,<br />Srilatha M
M Srilatha wrote:
...
in your example, the length property of array is a final variable and one cant modify the value of a final variable. So even if the property is public, it doesnt violate the encapsulation concept.
So its also well encapsulated.
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
M Srilatha wrote:Hi,
Encapsulation says that none of the instance variables should be public so that the variable values cant be changed directly accessing those variables. Instead all instance variables should be private and the class needs to have public methods to modify the value of private variables.
in your example, the length property of array is a final variable and one cant modify the value of a final variable. So even if the property is public, it doesnt violate the encapsulation concept.
So its also well encapsulated.
Prepare for 'OCA Java SE 8 certification' with eJavaGuru.com
Author of Manning's OCA Java SE 8 bookProgrammer I Certification Guide, OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that that can reduce the number of methods in the API without losing any functionality. if they implement the new design, which two OO principles will they be promoting?
Anton Sotnikov wrote:By the way I have a similar question:
A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that that can reduce the number of methods in the API without losing any functionality. if they implement the new design, which two OO principles will they be promoting?
The concept of encapsulation in object-oriented programming is to wrap data and methods that operate on the data into a single component by means of a class.
crispy bacon. crispy tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|