This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in the following code  RSS feed

 
Tom Riddle
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class X and Y is in the same package. Even you can access doStuff(), if it is of default access.

Naseem
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!