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 do you declare a destructor in java?
What is class forname used for?
Explain JMS in detail.
What super () does in java?
What is incompatible types in java?
What is a method in coding?
Can you call one constructor from another if a class has multiple constructors?
Give example to differentiate between call by value and call by reference.
How do I type unicode?
What is the super void?
What is an interface in java?
What is keyword and identifier?
How do you print array in java?
Why are parameters used in functions?
Explain public static void main(string args[]) in java.