Explain the differences between public, private, protected
and static?
Answer Posted / ranganathkini
Members marked public are accessible to members of any class
irrespective of the package.
Members marked private are only accessible to other members
of the same class.
Members marked protected are only accessible to other
members of the same class, members of a subclass and members
of other classes in the same package.
Member marked static are shared by all instances of that
class and hence r not related to any specific instance of
that class. Methods marked static cannot access non-static
members or fields of that class. But non-static members can
access static fields or methods.
| Is This Answer Correct ? | 111 Yes | 21 No |
Post New Answer View All Answers
What is the inheritance?
What is the meaning of immutable regarding string?
Name four container classes.
What is the abstraction?
Why are there no global variables in java?
whatis Home interface and Remoteinterface? with example?
Difference between object and reference?
Which class is the superclass for all the classes?
Can inner class be public in java?
how can i use a nonsynchronized hashtable?
If you do not want your class to be inherited by any other class. What would you do?
What is collection class in java? List down its methods and interfaces.
What is a generic type?
What is java util hashmap?
What is the access scope of a protected method?