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
Explain the init method?
Difference between ‘>>’ and ‘>>>’ operators in java?
what is encapsulation in java? Explain
Are arrays passed by reference in java?
What is the difference between a field variable and a local variable?
What is finalize method?
What is a finally block?
What is difference between iterator access and index access?
What is meant by memory leak?
How do you add an arraylist to an array in java?
Realized?
What is structure of java heap? What is perm gen space in heap?
Why we do exception handling in java and how many types of exceptions are there?
What does the three dot emoji mean?
What does I ++ mean?