0

Whats are the keyword of a class

public,protects, private

4th Sep 2017, 1:52 PM
gunjan
gunjan - avatar
5 Réponses
+ 5
They are access modifiers and help us implement Encapsulation (or information hiding). They tell the compiler which other classes should have access to the field or method being defined. private - Only the current class will have access to the field or method. protected - Only the current class and subclasses (and sometimes also same-package classes) of this class will have access to the field or method. public - Any class can refer to the field or call the method. This assumes these keywords are used as part of a field or method declaration within a class definition.
4th Sep 2017, 2:25 PM
P R
P R - avatar
+ 3
The private keyword denotes the least stable kind of method and provides the most restricted visibility. Private methods must be called with an implicit receiver, or, inversely, may never be called with an explicit receiver. The protected keyword also indicates an unstable method, but one with slightly different visibility restrictions. Protected methods allow explicit receivers as long as the receiver is self or an instance of the same class or subclass of self. The public keyword indicates that a method is stable; public methods are visible everywhere.
11th Dec 2017, 10:36 AM
Prabhat Thakur
Prabhat Thakur - avatar
0
hey !! keep it up !
15th Sep 2017, 6:16 AM
rahul negi
rahul negi - avatar
0
22nd Nov 2021, 10:57 AM
Nozimjon Mamasoliyev
Nozimjon Mamasoliyev - avatar
0
22nd Nov 2021, 10:57 AM
Nozimjon Mamasoliyev
Nozimjon Mamasoliyev - avatar