Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

obiect/class/method

 
Abdul Rahim1972
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want o know the difference between CLASS/OBJECT and METHOD in java.
Please explain in simple words.
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class is a container of variables and methods. A class should contain methods and variables which are related in some way. A method is a specific task or job which gets performed on a class.
An example might be a bank class. If you wanted to represent a bank as a class you would have variables and methods which have something to do with banking. So methods might be: depositMoney, withdrawMoney, and a variable might be currentBalance.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Class is a definition of a type of object and a place to store things that are valid across all objects of the Class (static variables).
An object of the Class is an instance of of something created from that definition.
Member variables (also known as instance variables) are places to store the STATE of the object at any given time.
Methods are written in the Class and define the BEHAVIOR of an object. You know - things that it can DO with instructions (code) on how to get it done.
Local variables (created inside methods or blocks) are temporary working variables that are disposed of as soon as the block or method is complete.

[This message has been edited by Cindy Glass (edited October 28, 2001).]
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abdul Rahim1972,
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at "JavaRanch Naming Policy" . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. We would like this forum to be as Professional as possible. Please choose a new name which meets the requirements.
Thanks,
Cindy
 
Marilyn de Queiroz
Sheriff
Posts: 9064
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think of a class as a cookie cutter. With a class (that contains fields and methods) you can create as many objects of that type class as you want to.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic