Share on Google+Share on Google+

SCJP Module-2 Question-11

The code given below checks the concepts of packages in java and prepares for the SCJP examination.

Which modifier should  used in place of  **** , so that it's subclass saved in other package can access " FixVariable() " method of it's super class ?

package NewPackage;
public class Example extends rose{
private int length;
*** void FixVariable( int a ) {
length = a;

// subclass in different package

import NewPackage.Example ;
public class SubExample extends Example {
SubExample() {
FixVariable( 201 );

Which modifier should used in place of ****, so that it's subclass 'SubExample' saved in other package can access 'FixVariable()'  method of  it's  super class ?





Answer :

2 & 3

Explanation :

 The protected modifier allows access by derived classes as well as classes in the same package. 

The private prevents any access from another class. 

The default access allows only access within the same package.


Posted on: July 8, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.