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
Is math an abstract class in java?
Can we use static class instead of singleton?
Explain java coding standards for interfaces?
What is a lightweight component?
Explain jvm, jre, and jdk?
What are the two types of exceptions in java? Which are the differences between them?
What are methods of a class?
What does exclamation mean in java?
Does isempty check for null?
What is skeleton and stub? What is the purpose of those?
4.1 Supply contracts (in the form of comments specifying pre- and post conditions) for the enqueue() method of the LinkedQueue class given in the Appendix. (2) 4.2 Let Thing be a class which is capable of cloning objects, and consider the code fragment: Thing thing1 = new Thing(); //(1) Thing thing2 = thing1; //(2) Thing thing3 = (Thing) thing1.clone(); //(3) Explain how the objects thing2 and thing3 differ from each other after execution of the statements. (
I want to persist data of objects for later use. What is the best approach to do so?
What is variable argument in java?
What do you mean by local variable and instance variable?
How do you clear an arraylist in java?