aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in the following code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in the following code" Watch "Doubt in the following code" New topic
Author

Doubt in the following code

Tom Riddle
Greenhorn

Joined: Jun 24, 2006
Posts: 8
Hi,
I have the following code

package test;

class X extends Y
{
public static void main(String argv[])
{
Object x = new X();
x.clone(); // Line 1
Y y = new X();
y.doStuff(); // Line2
}
}

class Y {
protected void doStuff() {
System.out.println("Base");
}
}

in the avove code Line1 throws an error saying "clone() has protected access in java.lang.Object" whereas Line2 compiles fine, but arent they similar? Can anyone please explain?

Regards,
Chaitra
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
class X and Y is in the same package. Even you can access doStuff(), if it is of default access.

Naseem


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in the following code