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


Please Help Members By Posting Answers For Below Questions

Is math an abstract class in java?

528


Can we use static class instead of singleton?

571


Explain java coding standards for interfaces?

618


What is a lightweight component?

581


Explain jvm, jre, and jdk?

553






What are the two types of exceptions in java? Which are the differences between them?

503


What are methods of a class?

536


What does exclamation mean in java?

563


Does isempty check for null?

542


What is skeleton and stub? What is the purpose of those?

532


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. (

1404


I want to persist data of objects for later use. What is the best approach to do so?

585


What is variable argument in java?

553


What do you mean by local variable and instance variable?

505


How do you clear an arraylist in java?

487