GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 216 of 492    Print  
why should every class in java extend Object class?

  
Total Answers and Comments: 4 Last Update: May 26, 2006     Asked by: kalyan 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
April 20, 2006 03:13:54   #1  
new user        

RE: why should every class in java extend Object class...

Object class is the super/base/parent class of every class(including user-defined classes).

So even if u don,t mention it, the user-defined classes extends Object class by default


 
Is this answer useful? Yes | No
April 24, 2006 08:27:30   #2  
ravi        

RE: why should every class in java extend Object class...

In java u can access the data through objects.Here Object class is a super/base/parent class for all the java classes,so it will be hold all class objects of java.And also whenever u can serialize the object into the Stream we must store as form of ObjectStream object only and at the time of Deserialize the object from the Streams, u must get it as form of Object class object only.After that u must casting the object to u r Knowing class.

example:  here file.txt is a file. And we can write the object into it,and read the object from it.

//write the object into the file,txt,and our class name is MyClass it object is "mco"

FileOutputStream fis=new FileOutputStream("file.txt");

ObjectOutpurStream oss=new ObjectOutputStream(fis);

os.writeObject(mco);

//read the object from the file.txt

FileIutputStream fos=new FileIutputStream(file.txt);

ObjectInputStream ois=new ObjectInputStream(file.txt);

MyClass myObj=(MyClass)ois;//here ois return the Object Class object only that's way we must the casting.


 
Is this answer useful? Yes | No
April 28, 2006 01:36:20   #3  
premisa Member Since: April 2006   Contribution: 4    

RE: why should every class in java extend Object class...

Hi

In order to reduce the excution time of a java program,we can make use of Constructor method to create an object which will extend to the given java class.

Hence  by using object class we can acceess the java program, while the class has the number of repeated function.

Thus Instead of calling the function/expreesion evertime bymake use of extending object class we can reduce the time consumption of the execution of the program quickly.


 
Is this answer useful? Yes | No
May 26, 2006 00:29:07   #4  
Sandhya        

RE: why should every class in java extend Object class...

Hey Guys,

Object class implements a set of methods and variables which are common to all the objects being created in the application. This is the main reason why we have Object class as a base class for all the other classes.

Some of the methods are:

hashCode() - this method creates a unique identity (or number) for each of the object being created in JVM.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape