This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instance and Class

 
ppavya india
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am new to Java Technology.Could anybody explain me what is the difference between instance and class.

Thanx in advance.
 
agSachin Agrawal
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class is a type like men is a class as me, you and millions on earth. They are of instance of class men. An instance have a physical existence like me sachin and u. But the class describes the behaviour of the instance. like all men have some common things like heavy voice, a beard etc.
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun has a convenient online tutorial on basic object oriented concepts and java programming. HTH.
 
ppavya india
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by agSachin Agrawal:
Class is a type like men is a class as me, you and millions on earth. They are of instance of class men. An instance have a physical existence like me sachin and u. But the class describes the behaviour of the instance. like all men have some common things like heavy voice, a beard etc.
 
ppavya india
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by agSachin Agrawal:
Class is a type like men is a class as me, you and millions on earth. They are of instance of class men. An instance have a physical existence like me sachin and u. But the class describes the behaviour of the instance. like all men have some common things like heavy voice, a beard etc.


Thanx man, and looking your help in future also.
 
Mahesh Bhatt
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Consider this, A class is an architectural design for a project. The instances are the actual concrete pieces that are then build based on this design. Apart from this please read the link to the tutorial given in the earlier post.

Hope it helps.
 
Suhaasi Karnik
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class is a structural and functional description of an object.
An object is an actual existence (instance) of that class. Different instances can have different structural features, but they all carry out the same functions basically.

Hence when you want to create a Book, you first create a class Book which has a variable called author, nameOfBook, category.

class Book
{
String author, nameOfBook, category;
Book(String a, String n, String c)
{
author = a; nameOfBook=n; category=c;
}
}

And then you create different objects of this class, such as

Book b1 = new Book("Peter van der Linden", "Just Java 2", "Software");
Book b2 = new Book("Carl Segan", "Contact", "Science Fiction");

Thus each object will be structurally similar but can have a different state, but will exhibit similar behaviour, since they all belong to the same class.
 
ppavya india
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx all,
...got the diff. between instance and class. Ok. Now one more quetion whta is the diff. between instance methods and class methods, if possible explain me with the help of one example.
Thanx in advance.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic