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 preparedstatement in java?
What is a key in java?
What is the difference between preparedstatement and statement in java?
How will you print number in reverse (descending) order in BST.
What is variable in java?
Can a class be private?
What is method in java ?
How many bits is a 64 bit byte?
What is use of set in java?
In which order the iterator iterates over collection?
Can we have two methods in a class with the same name?
When do we use synchronized blocks and advantages of using synchronized blocks?
What are Normalization Rules? Define Normalization?
Does string isempty check for null?
What is object cloning in Java?