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?
Printable View
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?
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).
It depends upon where your declare them.Quote:
What is the difference between a variable and an instance 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.Code:class Foo {
String name; // instance variable
static int count; // class variable
public void doStuff() {
int thingy = 0; // local variable
}
}
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").
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.
nevermind I got my answer thanks for the help.