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 are internal and external variables?
Why put method is used?
Difference between Linked list and Queue?
what is the use of pojo (plain old java objects)? how it is interact with crystal reports? pls urgent
Is a string literal?
What is java reflection api?
Is there any tag in htm to upload and download files?
What is the static field modifier?
What is the protected method modifier?
How do you clear a method in java?
When can we say that threads are not lightweight process in java?
Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?
Why is a constant variable important?
What are multiple inheritances? Is it supported by java?
what is the use of bean managed and container managed with example?