In: Computer Science
Give both an advantage and disadvantage of both private and public visibility as used in the design of an object (list four items)
Before starting to give your answer let's find out what inheritance and encapsulation is because this will help you to understand well about private and public class in oop.
Inheritance is a mechanism where you can Derive a class from another class
Encapsulation means the process to bind both the data and the function.
Now let's start with the question about differences of private and public visibility,remember the thing that only variable and methods and class can be defined as private and public
PUBLIC AND PRIVATE
Start with the word public means anyone can access where as private means that only members of the same class are allowed to access it .
1.
private - least access, best encapsulation
public - full access, no encapsulation
2.
Private means better security in terms of accessing the objects where as public means less security to access the objects.
3.
Methods that serve as the inner workings of your class and don’t output or display information here we use private
4.
In private methods that don’t add to the interface and do not collaborate with other classes can be used where as if we want collaboration with another class use public or protected
Kindly voteup if found useful