Home Tutorial Java Scjp Part2 SCJP Module-2 Question-11

 
 

Share on Google+Share on Google+
SCJP Module-2 Question-11
Posted on: July 8, 2010 at 12:00 AM
Advertisement
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 ?

1.private

2.public

3.protected

4.default(blank)

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.
Advertisement

Related Tags for SCJP Module-2 Question-11:


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.

Posted on: July 8, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com