• Post Reply Bookmark Topic Watch Topic
  • New Topic

protected method clone()  RSS feed

 
isbc chen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My questuion is why the protected method clone() from Object class can be called?
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because all classes are subclasses of Object. And subclassess can access protected members of their superclass.

And the clone() method in arrays is public.
 
Campbell Ritchie
Marshal
Posts: 56587
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a moot point whether you should actually override clone, but it is often overridden with public access
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!