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
Say any two properties in beans?
how to create daemon thread in java?
What is a pattern what is an anti pattern?
Can finally block be used without a catch?
What is the difference between the ">>" and " >>>" operators in java?
What is the difference between variable & constant?
What is integer valueof?
How many bits are in a sentence?
why not override thread to make a runnable? : Java thread
What is local declaration?
What are methods and how are they defined?
Why to use nested classes in java?
How do you implement polymorphism in our day to day life?
What happens when I use / and % with a negative numerator?
Is passing by reference faster?