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
In case of inheritance what is the execution order of constructor and destructor?
What is the do while loop syntax?
What are the 8 primitive data types in java?
What is the memory leak in java?
what do you understand by synchronization? Or what is synchronization and why is it important? Or describe synchronization in respect to multithreading? Or what is synchronization? : Java thread
Can you override private or static method in java?
What is public static?
What is the main purpose of serialization in java?
Is object a data type in java?
What is hashtable and explain features of hashtable?
Is char * a string?
Can a final variable be null?
What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. Import java.net.* Versus import java.net.socket)?
What's the purpose of using break in each case of switch statement?
How can we achieve thread safety in java?