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 function and method in java?
Why method overriding is used?
Why is a constant variable important?
What is the difference between stored procedure & function?
Does google use java?
How we can run a jar file through command prompt in java?
What is the differences between heap and stack memory in java? Explain
Is void a type?
What is the difference between JDK and JVM?
What is the primitive type byte?
what are synchronized methods and synchronized statements? : Java thread
When wait(), notify(), notifyall() methods are called does it releases the lock or holds the acquired lock?
What is included in core java?
Does java isempty check for null?
Explain the importance of thread scheduler in java?