Notes by Ho-Seop Kim
First declare an object, then create it
C++:
int a[100]; // declare and allocate space (on stack)Java:
int[] a = new int[100];Illegal subscript is handled by Java system (via exception)
int a[] = new int[100];
point p; // just creates reference
point p = new point(); // constructor
MembersMembers are
Methods (code/functions) // unlike C/C++, method must have a return type
Constructor // no return type
point p = new point();Sometimes we need variable generic to class. But there's no global variable in Java. All data should be in a class. With public static int howmany = 0; we can use point.howmany.
point q = new point(1, 2);+-----+ point
p ---> |x = 0| +-----------+
|y = 0| |howmany = 2|
+-----+ +-----------++-----+
q ---> |x = 1|
|y = 2|
+-----+
int a = 1; public class
test{
main(){
static public void main(String[] args){
a = 0;
a = 0;
}
}
}