File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Java Object class 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 » Java » Beginning Java
Bookmark "Java Object class" Watch "Java Object class" New topic
Author

Java Object class

Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
why object class has protected method(clone,finalize) ? As we know that every class is child of Object class then does it make sense?
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Beginner question, not Advanced forum material.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14423
    
  23

Good question. The designers of the Object class probably made these methods protected to give you a hint that you should never call these methods directly - even though it doesn't really make it impossible to do so.

And welcome to JavaRanch!
[ August 21, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Saurabh Patil
Ranch Hand

Joined: Dec 11, 2005
Posts: 45

Originally posted by Jesper Young:
Good question. The designers of the Object class probably made these methods protected to give you a hint that you should never call these methods directly - even though it doesn't really make it impossible to do so.

And welcome to JavaRanch!

[ August 21, 2007: Message edited by: Jesper Young ]



Can you please explain "call these method directly"!! :confused"


All for one and one for all!
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Try calling the protected clone() method of class A from class B, where A and B are not superclass and subclass. You can't.

If you need to be able to do that sort of thing, you must override the protected clone() method with a public one.

But trying to learn much from the clone feature of Java is a mistake, because it was one of the first features added to the language and is very badly designed, by today's standards.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14423
    
  23

Originally posted by Saurabh Patil:
Can you please explain "call these method directly"!!

What I mean with that is that you should not write a Java program that calls the finalize() method of any object. This is a special method that the JVM calls when necessary - when the garbage collection process is cleaning up the object.

For the clone() method, what I said is actually not true. If you want objects of your class to be cloneable, you should make your class implement interface Cloneable and provide a public clone() method in your class, according to the documentation of interface Cloneable:
By convention, classes that implement this interface should override Object.clone (which is protected) with a public method. See Object.clone() for details on overriding this method.
Mintoo kumar
Ranch Hand

Joined: Aug 21, 2007
Posts: 61
Thanks a ton for answers.

But still my questation is "Why in Object class ".As its a Father of all the born java classes?

Although,i do agree that protected method is for overriding purposes.No doubt.if you have public method you can also override these methods in your child class?

So ,these "protected" serve any specfic means ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Object class