CS1122___Week_2___Objects_and_Classes
CS1122___Week_2___Objects_and_Classes
▶ When you make a new object with a class, the data type of that
object is the class name.
▶ A Constructor
▶ Non-static Methods
▶ Instance Variables
// A constructor !
public Counter () {
this . value = 0;
}
// I ’ ve overloaded it !
public Counter ( int value ) {
this . value = value ;
}
counter . incVal () ;
System . out . println ( counter . getVal () ) ;
}
▶ When you want to refer to the object itself in a method, you use
the key word this.
▶ Objects are data and the methods that are tied to that stored
data.