Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


Explain the differences between public, private, protected
and static?

Answers were Sorted based on User's Feedback



Explain the differences between public, private, protected and static?..

Answer / ranganathkini

Members marked public are accessible to members of any class
irrespective of the package.

Members marked private are only accessible to other members
of the same class.

Members marked protected are only accessible to other
members of the same class, members of a subclass and members
of other classes in the same package.

Member marked static are shared by all instances of that
class and hence r not related to any specific instance of
that class. Methods marked static cannot access non-static
members or fields of that class. But non-static members can
access static fields or methods.

Is This Answer Correct ?    111 Yes 21 No

Explain the differences between public, private, protected and static?..

Answer / ankit porwal

public: &#9835;
a method or field defined by public is accessible by all
other methods and fields of that program anywhere.
private: &#9835;
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: &#9835;
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

Explain the differences between public, private, protected and static?..

Answer / quins welfred

this is not true in all cases.

Is This Answer Correct ?    19 Yes 19 No

Explain the differences between public, private, protected and static?..

Answer / manne ranjith

public-->inherite the protected members as preotected in
drived class and pubic members wiull be public in derived
class

protected--->pubic and protecated members of the base class
will become protected in derived class

Private-->pubilc and proteacted members will become private
in derived class

static--->Method is defined by static cannot access non-static
members or fields of that class. But non-static members can
access static fields or methods.

Is This Answer Correct ?    28 Yes 32 No

Post New Answer



More Core Java Interview Questions

How do you use equal in java?

0 Answers  


Can we access private data outside of the class directly in java programming language? Why There is no runtime checking in java, which leads to access the private data directly outside of a class?

5 Answers   Google,


What are some examples of variable costs?

0 Answers  


string is immutable? right every one knows that, my question is it advantage or disadvantage making string immutable?

5 Answers   HCL,


What are the 8 data types in java?

0 Answers  






v-model life cycle

0 Answers   Virtusa,


Can Applet have constructors?

5 Answers   Infosys,


How do you create a reference in java?

0 Answers  


What is final?

0 Answers  


What are the four corner stones of oop?

0 Answers  


I have a class which is abstract which contains only the abstract methods. This is similar to an interface. Then, if i have given a choice to choose one of them. Which one i have to choose and why?

4 Answers  


What is an object's lock and which object's have locks in java programming?

0 Answers  






Categories