GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE
Go To First  |  Previous Question  |  Next Question 
 J2EE  |  Question 18 of 104    Print  
can we declare class as protected?
what is the scope for this class?

  
Total Answers and Comments: 35 Last Update: May 19, 2008     Asked by: suresh 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: dipl. ing. Dan
 

Some people might get confused by the many posts. The correct answer to the question "can we declare class as protected?" is YES, BUT only as an inner class. A 'normal' class cannot be protected or private.

// 'Normal' class - only default or public allowed

public class ProtectedOrNot {

  // Inner class - public, default, protected, private allowed

  protected class InnerClass {

  }

  public static void main(String[] args) {

  }

}



Above answer was rated as good by the following members:
iitd.mayank
  Sorting Options  
  Page 1 of 4   « First    1    2    3    >     Last »  
February 25, 2006 14:19:14   #1  
vimal        

RE: can we declare class as protected?what is th...

hi

no the class can not be protected. the error will be like modifier protected not allowed here.


 
Is this answer useful? Yes | No
February 26, 2006 08:07:00   #2  
mnj_rt Member Since: February 2006   Contribution: 2    

RE: can we declare class as protected?what is th...
the classs can be protected so that it can ve package access only
 
Is this answer useful? Yes | No
February 26, 2006 23:34:32   #3  
murugan        

RE: can we declare class as protected?what is th...
No No we should not declare the class as protected or private the compiler will show the error only possible modifiers are public and default
 
Is this answer useful? Yes | No
February 28, 2006 10:30:42   #4  
navneet raushan        

RE: can we declare class as protected?what is th...
Yeah u can declare class as protected
 
Is this answer useful? Yes | No
March 01, 2006 14:26:04   #5  
Sachin Soni        

RE: can we declare class as protected?what is th...
Yes we can declare a class as protected however its sub-classes (inherited) can only use the objects of that class then. It will not be possible to access the functions of that class with other class's objects.
 
Is this answer useful? Yes | No
March 01, 2006 18:39:42   #6  
minnie        

RE: can we declare class as protected?what is th...
We can not declare a class protected the compiler will give an error protected not allowed ahere
 
Is this answer useful? Yes | No
March 05, 2006 01:11:40   #7  
kotesh Member Since: February 2006   Contribution: 2    

RE: can we declare class as protected?what is th...
1. No You can't declare a class as protected. because compiler will give you Compile time error.2. You can decalre a class a public or default. if you don't mention any access specifier by default it will take class as default access specifier
 
Is this answer useful? Yes | No
March 06, 2006 00:47:46   #8  
narendra        

RE: can we declare class as protected?what is th...

we can declare the class as protected only the functionality can be used subclasses.


 
Is this answer useful? Yes | No
March 07, 2006 18:28:02   #9  
ananthi        

RE: can we declare class as protected?what is th...
Yes.. A class can be declared as protected.But it should not be the outermost class.Example:public class A{ protected class B { }}
 
Is this answer useful? Yes | No
March 07, 2006 23:37:24   #10  
Shyam sankar        

RE: can we declare class as protected?what is th...

HI

class can not be declared as protected....


 
Is this answer useful? Yes | No
  Page 1 of 4   « First    1    2    3    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape