Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What is the difference between an object and an instance in java?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 02-03-2009
Member
 
Join Date: Feb 2009
Posts: 8
What is the difference between an object and an instance in java?
  

Hi,

What is the difference between an object and an instance in JAVA?

Reply With Quote
  #2  
Old 02-03-2009
Member
 
Join Date: Jan 2009
Posts: 44
Re: What is the difference between an object and an instance in JAVA?

object has a memory allocated to it during its creation using the syntax
Code:
classname var=new classname();
But for instance creation it returns only a pointer refering to an object,syntax is
Code:
classname varname;
Reply With Quote
  #3  
Old 02-03-2009
Member
 
Join Date: Apr 2008
Posts: 1,993
Re: What is the difference between an object and an instance in JAVA?

Instance in java...

An actual object of a particular class. An instance of a class is created using the new operator followed by the class name.

Object in java...

When we define a class that does not extend any other class, it implicitly extends java.lang.Object. Also, an anonymous class based on an interface.

In general we think instance and objects are same, but they are incorrect.

instance will have the both class definiation and the object defination where as in object it will have only the object defination.
Reply With Quote
  #4  
Old 02-03-2009
Member
 
Join Date: May 2008
Posts: 2,283
Re: What is the difference between an object and an instance in JAVA?

An object and an instance are one in the same. The difference is between classes and objects.

Anything that is static in a class becomes propery of the class itself. These are things like static variables and static methods.

To use things that belong to the class itself, no instance of that class is required. No object is required.

Objects, on the other hand, are instances of a class. Any non static method defined in a class requires an instance for it to be used.

An example of a method that belongs to a class is the Collections.sort() method. This can be invoked simply by using the actual class.

However, adding an object to a LinkedList actually requires an instance of that class to be created.

So in short, an object is an instance of a class, so objects and instances are the same thing.
Reply With Quote
  #5  
Old 02-03-2009
Member
 
Join Date: May 2008
Posts: 2,373
Re: What is the difference between an object and an instance in JAVA?

Objects are key to understanding object-oriented technology.

Instance Method is a subroutine or function designed to work on the current object. Methods are always part of some class.
An instance method has access to all the instance variables, other instance methods, as well as the static class-as-a-whole methods and variables.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #6  
Old 02-03-2009
Member
 
Join Date: May 2008
Posts: 2,001
Re: What is the difference between an object and an instance in JAVA?

The main difference between abstract class and interface is,

1. Abstract class has the constructor, but interface doesn't have.

2. Main reason is abstract class contain the instance variable, that why it has
the constructor, where as interface has only constants (final variables and
ABSTRACT METHODS).

3. A class which can implement the interface, is not implement all methods which
are declared in interface , such class is declared as abstract class. that mean
abstract class is a subtype of an interface.

This is my conclusion. If you have an queries let me know.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is the difference between an object and an instance in java?"
Thread Thread Starter Forum Replies Last Post
About instance variables in java Khaled11 Software Development 1 19-03-2010 02:38 PM
Differentiation between C++ object and instance Ram Bharose Software Development 4 06-02-2010 12:40 PM
What is Instance variables in Java? Owen Fernandes Software Development 5 23-01-2010 07:27 AM
Object reference not set to an instance of an object KAIRU26 Software Development 3 05-09-2009 08:14 PM
Object test = new Object() <-- Java, best way in C++ ADISH Software Development 3 25-10-2008 02:32 PM


All times are GMT +5.5. The time now is 02:37 AM.