Objects encapsulate data members and method members, and are instances of classes which specify these members. A class acts as a blueprint for objects, defining the data and methods, and is used to construct objects in memory at runtime. An example Point class is provided, with private data members x and y representing the coordinates of a point. Getter and setter methods allow accessing and modifying the coordinate values.
Objects encapsulate data members and method members, and are instances of classes which specify these members. A class acts as a blueprint for objects, defining the data and methods, and is used to construct objects in memory at runtime. An example Point class is provided, with private data members x and y representing the coordinates of a point. Getter and setter methods allow accessing and modifying the coordinate values.
Objects encapsulate data members and method members, and are instances of classes which specify these members. A class acts as a blueprint for objects, defining the data and methods, and is used to construct objects in memory at runtime. An example Point class is provided, with private data members x and y representing the coordinates of a point. Getter and setter methods allow accessing and modifying the coordinate values.
CSE205 Object Oriented Programming and Data Structures Page 1
1. Objects and Classes
An object encapsulates data members and method members. Objects are instances of classes and a class specifies the data and method members of objects. A class is like a blueprint for objects of the class and is used to construct the object in memory at runtime. CSE205 Object Oriented Programming and Data Structures Page 2
1. Objects and Classes :: Example Class Point
//********************************************************************************* // CLASS: Point (declared in Point.java) //********************************************************************************* public class Point { // A point in the Cartesian plane is located at (x, y) where x and y form the // coordinates of the point. private double x; private double y; // Constructor. public Point(double initX, double initY) { setX(initX); setY(initY); } // Accessor method for x. public double getX() { return x; } // Accessor method for y. public double getY() { return y; } CSE205 Object Oriented Programming and Data Structures Page 3
1. Objects and Classes :: Example Class Point (continued)
// Mutator method for x. public void setX(double newX) { x = newX; } // Mutator method for y. public void setY(double newY) { y = newY; } }