Results 1 to 6 of 6
  1. #1
    intel 4004 is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default 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...

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default 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.

  3. #3
    intel 4004 is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: Class, Methods, Statements, Object?

    I was reading that too. Each book introduce different things and its making it confuse...

  4. #4
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    107
    Rep Power
    0

    Default Re: Class, Methods, Statements, Object?

    the whole ".java" is a source file?
    Each public class is inside of one source file with the name of the class and an extension of .java

    Whats in it is a "class"
    A class has 1) variables, 2) constructors, and 3) methods in it

    "method" (only one) is in 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".

    "statements" (more than one) is in the "method"
    Yes, a method is made up of statements. A method can have more than one statement in it.

    So what is an object?
    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.

  5. #5
    Cyclingjico is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default 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.

  6. #6
    intel 4004 is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: Class, Methods, Statements, Object?

    This helps a lot! Thanks :D

Similar Threads

  1. Replies: 1
    Last Post: 10-16-2012, 02:58 PM
  2. Call object methods from another class
    By africanhacker in forum New To Java
    Replies: 16
    Last Post: 03-22-2011, 01:10 AM
  3. Methods in Object class
    By Navatha in forum New To Java
    Replies: 1
    Last Post: 09-28-2010, 11:17 PM
  4. 'Class' Object and calling Static Methods?
    By mikeiz404 in forum Advanced Java
    Replies: 3
    Last Post: 01-24-2009, 12:58 PM
  5. 'Class' Object and calling Static Methods?
    By mikeiz404 in forum New To Java
    Replies: 2
    Last Post: 01-24-2009, 05:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •