what is an object class

S

syntax

hi ,i am not clear about object class...is it in a package??

say, i am writing a class MY_CLASS ...does methods and fields of
object class implicitly will come to MY_CLASS ???

can you explain a bit about the OBJECT class??

i have also question on two methods viz valueOf() and toString()

what does they do?? and which class they belong to???

these two methods are very useful i think....can anybody tell about
these two methods.

thanks
 
C

Christophe Vanfleteren

syntax said:
hi ,i am not clear about object class...is it in a package??

say, i am writing a class MY_CLASS ...does methods and fields of
object class implicitly will come to MY_CLASS ???

Any class you write will automatically extends java.lang.Object

When you write

public class MyClass {
...
}

the compiler will treat it as if you had written
public class MyClass extends java.lang.Object
can you explain a bit about the OBJECT class??

It's the base class of which all other classes are derived. Hence the
"everything is an object" mantra of java (primitives such as int,
float, ... not counted offcourse :)
i have also question on two methods viz valueOf() and toString()

what does they do?? and which class they belong to???

toString() is defined in java.lang.Object.

valueOf() is defined in whatever class it can perform a usefull function.

String for example has such a method.
these two methods are very useful i think....can anybody tell about
these two methods.

thanks

But may I suggest that you do some more reading in the tutorial, before you
ask such things again (especially in this group, c.l.j.help is a better
choice for these questions)?

Tutorial: http://java.sun.com/docs/books/tutorial/
 
J

Joona I Palaste

syntax said:
hi ,i am not clear about object class...is it in a package??

You mean the class Object? Yes, it's in a package. The package is
called java.lang, which makes the full name of the class
java.lang.Object.
say, i am writing a class MY_CLASS ...does methods and fields of
object class implicitly will come to MY_CLASS ???

All public methods and fields, yes.
i have also question on two methods viz valueOf() and toString()
what does they do?? and which class they belong to???

Any class that defines them. What they do depends on the class.
Every class has a toString() method, they inherit it from the Object
class if not otherwise. The default implementation of toString() is
to print the class name and the hash code, but you can override it to
print whatever you want. The method valueOf() is not present in all
classes. It's present in java.lang.String for instance, and there it
simply calls toString() on the object that it gets as a parameter.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Outside of a dog, a book is a man's best friend. Inside a dog, it's too dark
to read anyway."
- Groucho Marx
 
E

Ed Thompson

syntax said:
hi ,i am not clear about object class...is it in a package??

say, i am writing a class MY_CLASS ...does methods and fields of
object class implicitly will come to MY_CLASS ???

can you explain a bit about the OBJECT class??

i have also question on two methods viz valueOf() and toString()

what does they do?? and which class they belong to???

these two methods are very useful i think....can anybody tell about
these two methods.

thanks
check out Thinking in Java! at http://www.reztek.com/download.php
First couple of chapters are a real help on this topic!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top