Results 1 to 6 of 6
- 12-28-2012, 05:20 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Class, Methods, Statements, Object?
I read a few Java books and I always get confuse of the terminology. So...
the whole ".java" is a source file?
Whats in it is a "class"
"method" (only one) is in a "class"
"statements" (more than one) is in the "method"
So what is an object?
Trying to learn Java for years and I never able to learn it well...
- 12-28-2012, 06:51 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Class, Methods, Statements, Object?
This tutorial can answer your questions, Trail: Learning the Java Language: Table of Contents (The Java™ Tutorials). Please take some time to read and understand it.
Website: Learn Java by Examples
- 12-28-2012, 07:04 AM #3
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Re: Class, Methods, Statements, Object?
I was reading that too. Each book introduce different things and its making it confuse...
- 12-28-2012, 07:17 AM #4
Member
- Join Date
- Dec 2012
- Posts
- 74
- Rep Power
- 0
Re: Class, Methods, Statements, Object?
Each public class is inside of one source file with the name of the class and an extension of .javathe whole ".java" is a source file?
A class has 1) variables, 2) constructors, and 3) methods in itWhats in it is a "class"
No, a class can have more than one method. A method is a part of the program that is broken into pieces. A method can take parameters and can return a result. Some languages have "functions", but in Java, they're called "methods"."method" (only one) is in a "class"
Yes, a method is made up of statements. A method can have more than one statement in it."statements" (more than one) is in the "method"
If I were developing a card-playing program, I might want to have a class called Card. Then I would create a deck of cards, making 52 instances of the Card class, or 52 objects of type Card. For example, one card object would be the 5 of Spades and another would be the Queen of Hearts. It's important to understand that there is only one Card class but there are 52 card objects.So what is an object?
- 12-28-2012, 09:55 AM #5
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
Re: Class, Methods, Statements, Object?
Another way to think of classes and objects and such:
Have you ever played any form of role playing game? If so, this may help you to understand.
Class: For example, when you start the game you must choose between Fighter, Magic User or Rogue. When you choose one, and give it a name, you have just created an Instance of whatever Class you chose.
Method: These are the actions of a Class. For instance, every Class has some form of standard attack. So the base class that Fighter, Magic User and Rogue are derived from, Player (This is inheritance, a class can extend the construct of another class, thus inheriting its basic construct). In order to make the basic attack somewhat unique between the three classes, we can override the basic attack and add some uniqueness to it while still keeping the basic concept of the unique attack (this allows us to use the same name for the Method)
In order to not replicate many of the tutorials out there, I will not continue any further. hopefully this may help to dispel some of your confusion, and may make understanding what is going on in the tutorials a tad bit easier.
- 01-03-2013, 03:05 AM #6
Member
- Join Date
- Dec 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Accessing methods from object in another class.
By blug in forum New To JavaReplies: 1Last Post: 10-16-2012, 02:58 PM -
Call object methods from another class
By africanhacker in forum New To JavaReplies: 16Last Post: 03-22-2011, 01:10 AM -
Methods in Object class
By Navatha in forum New To JavaReplies: 1Last Post: 09-28-2010, 11:17 PM -
'Class' Object and calling Static Methods?
By mikeiz404 in forum Advanced JavaReplies: 3Last Post: 01-24-2009, 12:58 PM -
'Class' Object and calling Static Methods?
By mikeiz404 in forum New To JavaReplies: 2Last Post: 01-24-2009, 05:10 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks