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
How will you calculate the depth of a binary tree if the tree contains 15 nodes?
What is the difference between inner class and nested class?
How to sort a collection of custom Objects in Java?
What is a singleton factory?
What do you understand by access specifiers in Java?
How to sort an array in java without using sort method?
String class is defined under which package in java?
What is the benefit of inner classes in java?
What is byte value?
Is java a utf 8 string?
What’s the difference between callable and runnable?
Why we go for collections in java?
What is a numeric format?
What is a class instance variable?
Why char array is favored over string for the storage of passwords?