Explain the differences between public, private, protected
and static?
Answer Posted / ankit porwal
public: ♫
a method or field defined by public is accessible by all
other methods and fields of that program anywhere.
private: ♫
u can't access the private members or methods outside the
class they are only accessible inside the class.
eg: if u have "org.iitk.ankit.abc.java;" and another file in
the package "org.iitk.ankit.xyz.java;".
in this case u can't access the private methods of abc.java
class in the xyz.java file's calsses.
protected: ♫
in case of protected u can access the protected members in
the same package but can't access outside that package.
eg: means u can access members of abc.java in xvz.java.
b'coz they are in the same directory.
but not accessible in iitk directories files.
for more detail contact me at
email: crystal.brawal@gmail.com
| Is This Answer Correct ? | 24 Yes | 11 No |
Post New Answer View All Answers
What is a parameter in a function?
Explain throw keyword in java?
What does provide mean construction?
In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?
Can a final method be overloaded?
What are the types of exceptions?
How can we make string upper case or lower case?
What is getclass () getname () in java?
What is difference between word and integer?
What are the drawbacks of reflection?
What is a file pointer?
what do you mean by java annotations?
what is interface in java? Explain
What is set in java?
how to create daemon thread in java?