:: 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 abstract method with example? Virtusa 6
What is race condition ?? (Threading concept) TCS 2 sept10 TCS 3
System.out.println(101/14) what is the output? a)6 b)14 c)7.14 d)0 Accenture 8
When you Click a Button, What event will be fired?   5
When will we use class loader?   2
what is meant by multicast?   1
How to call a Stored Procedure from JDBC? Satyam 4
While opening the file, what type of exceptions can be caught?   3
What will be the output of the program? public class Test { public static void main(String args[]) { ArrayList<String> list = new ArrayList<String>(); list.add("2"); list.add("3"); list.add("4"); list.add("5"); System.out.println("size :"+list.size()); for(int i=0;i<list.size();i++) { list.remove(i); } System.out.println("size after:"+list.size()); } } Rolta 5
Differentiate Vector and ArrayList? Wipro 4
What is a compilation unit?   2
What is meant by Java interpreter?   4
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.   ::