Results 1 to 7 of 7
  1. #1
    physalis123 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Newbie Questions

    The most embarrassing question but always bugs me every time I read in my book.
    What is a type in java?
    What is the difference between a variable and an instance variable?

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by physalis123 View Post
    What is a type in java?
    Type is simply that, the type of the variable. For example int, long, double, String, Point, Foo, Bar etc. The first three are primitive types. The last four are reference types (classes).
    What is the difference between a variable and an instance variable?
    It depends upon where your declare them.
    Java Code:
    class Foo {
        String name; // instance variable
        static int count; // class variable
    
        public void doStuff() {
            int thingy = 0; // local variable
        }
    }
    An instance variable is so called because each time you create an object of that class they each get their own instance of that variable. The class variable means that it belongs to the class and not an instance. So each object you create uses the same variable. The difference is very important to understand. Lastly the local variable is local to that code block (if statement, loop or method) and cannot be used outside of that code block.

  3. #3
    physalis123 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Type is simply that, the type of the variable. For example int, long, double, String, Point, Foo, Bar etc. The first three are primitive types. The last four are reference types (classes).
    Oh I remember that, so an example sentence I am struggling with is "An object of type String is a sequence of characters." Then talks about string literals with examples ("2468") and ("I must/n go home").

    Quote Originally Posted by Junky View Post
    An instance variable is so called because each time you create an object of that class they each get their own instance of that variable. The class variable means that it belongs to the class and not an instance. So each object you create uses the same variable. The difference is very important to understand. Lastly the local variable is local to that code block (if statement, loop or method) and cannot be used outside of that code block.
    to summarize, instance variable is a duplicated variable every time the same class is made?

    Class variable is a variable only made once but used by classes in need?

    local variable is found and used in a certain code block.

    how to superclass and subclass work for these variables? How do you tell them apart since variables don't have headers.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by physalis123 View Post
    how to superclass and subclass work for these variables? How do you tell them apart since variables don't have headers.
    It depends upon the access modifier. Public and protected variables are inherited. Private variables are not. I have no idea what you mean by headers.

  5. #5
    physalis123 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    I have no idea what you mean by headers.
    I sorta meant like method headers and variables don't have those. How do you tell the variables apart.

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by physalis123 View Post
    How do you tell the variables apart.
    What variables are you talking about?

  7. #7
    physalis123 is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Need help with some questions
    By El_Davidos in forum New To Java
    Replies: 5
    Last Post: 11-23-2010, 10:13 AM
  2. Several newbie questions, applet help mostly
    By gymangel812 in forum New To Java
    Replies: 4
    Last Post: 02-16-2010, 02:00 AM
  3. Couple of newbie questions
    By ananasman in forum New To Java
    Replies: 11
    Last Post: 11-20-2008, 11:54 PM
  4. Some newbie questions about shortcuts
    By nefigah in forum Eclipse
    Replies: 2
    Last Post: 07-29-2008, 08:25 AM
  5. Newbie with questions
    By buzzdsm in forum New To Java
    Replies: 14
    Last Post: 06-05-2008, 04:11 PM

Posting Permissions

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