tailieunhanh - Object-Oriented Programming - Lecture 2: Classes and Objects
Object-Oriented Programming - Lecture 2: Classes and Objects presents Class, Object, More on class, Enum types, Package and the class path, Documentation comments for class, Number and String. | Object-Oriented Programming Lecture 2: Classes and Objects Dr. Lê H!ng Ph"#ng -- Department of Mathematics, Mechanics and Informatics, VNUH July 2012 1 Friday, July 27, 12 Content ✦ Class ✦ Object ✦ More on class ✦ Enum types ✦ Package and the class path ✦ Documentation comments for class ✦ Number and String 2 Friday, July 27, 12 Class ✦ Recall that a class is a blueprint from which individual objects are created. ✦ Classes are defined in the following way: class MyClass { // field, constructor, and // method declarations } ✦ The class body contains all the code that provides for the life cycle of the objects created from the class: ✦ Constructors for initializing new objects ✦ Declarations for the fields that provide the state of the class ✦ Methods to implement the behavior of the class and its objects 3 Friday, July 27, 12 Class ✦ More complicated declaration of class: class MyClass extends MySuperClass implements YourInterface { // field, constructor, and // method declarations } ✦ This means that MyClass is a subclass of MySuperClass and that it implements the YourInterface interface. ✦ You can add access modifiers like public, protected, private at the beginning, which determine what other classes can access MyClass (discuss later). 4 Friday, July 27, 12 Declaring member variables ✦ There are several kinds of variables: ✦ ✦ Variables in a method or a block of code--these are called local variables. ✦ ✦ Member variables in a class--these are called fields. Variables in method declaration--these are called parameters. The Bicycle class uses the following lines of code to define its fields: int cadence; int speed; int gear; 5 Friday, July 27, .
đang nạp các trang xem trước