:: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Categories >> Software >> Java Related >> Java J2EE >> Core Java


 Core Java interview questions  Core Java Interview Questions (1722)
 Advanced Java interview questions  Advanced Java Interview Questions (331)
 Swing interview questions  Swing Interview Questions (44)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (196)
 JDBC interview questions  JDBC Interview Questions (187)
 JMS interview questions  JMS Interview Questions (9)
 SunOne interview questions  SunOne Interview Questions (3)
 J2EE interview questions  J2EE Interview Questions (71)
 Weblogic interview questions  Weblogic Interview Questions (147)
 Websphere interview questions  Websphere Interview Questions (14)
 Java Networking interview questions  Java Networking Interview Questions (20)
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions (87)
Explain the differences between public, private, protected 
and static?
 Question Submitted By :: Core-Java
I also faced this Question!!     Answer Posted By  
# 1
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
# 2
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 ";" and another file in
the package ";".
in this case u can't access the private methods of
class in the 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 in
b'coz they are in the same directory.
but not accessible in iitk directories files.
for more detail contact me at
Is This Answer Correct ?    24 Yes 10 No
Ankit Porwal
# 3
this is not true in all cases. 
Is This Answer Correct ?    19 Yes 19 No
Quins Welfred
# 4
public-->inherite the protected members as preotected in
drived class and pubic members wiull be public in derived

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
Manne Ranjith

Other Core Java Interview Questions
  Question Asked @ Answers
What is singleton class? AMDOC 16
I have a String s = java; What is the output when I say s.replaceAll('j', 'k'); Also what is the value of s after replacing? KPIT 7
What primitive Java types? Howmany are they and what are their names?   3
what is meta-Inf? Polaris 2
what is the use of clone() in real time scenario? Quinnox 2
java program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors. HCL 7
What is meant by Java ? CMC 2
What is the purpose of having the concept of overloading? Ness-Technologies 6
What are null interfaces in JAVA ? and give me some examples?   5
How TreeMap sorts the objects inside it?? suppose if have include one employee object and one car object. On what basis it will sort?   5
How many objects are created for a singleton class Ness-Technologies 7
what is use of marker interface? give me good example?   2
For more Core Java Interview Questions Click Here 

Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
Copyright 2013  All Rights Reserved.   ::