Difficulty: Intermediate | Prerequisites: Functions and Modular Programming (Chapter 6) notes.
Big picture
Object-oriented programming (OOP) is the organising model for most real-world Java applications. Where Chapter 6 taught you to package logic into functions, Chapter 7 teaches you to package both data and functions together into classes. A class is a blueprint; an object is a thing built from that blueprint. The exam tests this distinction directly, along with encapsulation (data hiding with private), constructors, and the getter/setter pattern. If you missed the functions chapter, go back and cover it first, because every method inside a class is a function.
A class bundles data (member variables) and behaviour (methods) into one unit. Objects are instances of a class, created in memory only when you instantiate them. Encapsulation hides internal data behind private access and exposes it through public getter and setter methods. Constructors initialise objects automatically when they are created; they have no return type (not even void). A class can have multiple constructors through overloading. In C++ contexts, destructors (prefixed with ~) clean up when an object is destroyed.
Class
A blueprint or template that defines a set of member variables (data) and methods (behaviour). A class declaration does not create an object in memory; it only describes the structure. Think of it as the architectural plan for a house, not the house itself.
Object
An instance of a class, created in memory when you use the new keyword. Each object has its own copy of the member variables defined in the class. In simple terms, if the class is the blueprint, the object is the actual house you built from it.
Abstract Data Type (ADT)
A data type that specifies the values it can hold and the operations it can perform, while hiding the implementation details of how those operations work. Think of it as a contract: it tells you what you can do, not how it is done internally.
Encapsulation
The OOP principle of bundling data (attributes) and the methods that operate on that data into a single unit (class), while restricting direct access to the internal data. In simple terms, you put the data and its functions in the same box and lock the data so outsiders can only use it through approved methods.
Constructor
A special public method that is automatically invoked when an object is created. It has the same name as the class and has no return type (not void, not int, nothing). Its purpose is to initialise the object's member variables.
Default constructor
A constructor that takes no parameters. It provides standard initialisation values.
Overloaded constructor
A constructor that accepts one or more parameters, allowing you to initialise an object with custom values at creation time. A class can have both a default and one or more overloaded constructors.
Destructor (C++ context)
A special method that is called when an object is destroyed, used for cleanup (freeing memory, closing files). In C++, the destructor name begins with a tilde (~) followed by the class name. Java handles cleanup differently through garbage collection.
Accessor (getter)
A public method that returns the value of a private member variable. Commonly named with a get prefix, e.g. getGpa(). Accessors are "get" functions, not "set" functions.
Mutator (setter)
A public method that changes the value of a private member variable. Commonly named with a set prefix, e.g. setGpa(double gpa). Mutators are "set" functions.
private (access specifier)
Member variables and methods declared private can only be accessed from within the same class. They are invisible to outside code, enforcing data hiding.
public (access specifier)
Members declared public can be accessed from any other class. Constructors, getters and setters are typically public.
Dot operator (.)
Used to access public members (methods and variables) of an object from outside the class. Example: student1.getGpa().
Class vs object
A class is a declaration, a template. Defining a class does not create an object in memory.
An object is created by instantiating the class with the new keyword: Student s1 = new Student("Alice", 3.8);
Each object gets its own copy of the class's member variables.
Encapsulation and data hiding
The core idea: bundle data and methods together in one class, and hide the data behind private access.
Outside code cannot read or modify private variables directly. Access goes through public getter (accessor) and setter (mutator) methods.
This protects the data from being changed in unexpected ways and makes the class easier to maintain.
Constructors
A constructor is called automatically when you create an object.
It has the same name as the class and no return type at all (not void).
A default constructor takes no arguments and sets member variables to standard initial values.
An overloaded constructor takes one or more arguments, letting you set custom initial values.
A class can have multiple constructors (through overloading), as long as their parameter lists differ.
Example (the Student class from the exam):
public class Student {
private String name;
private double gpa;
public Student(String name, double gpa) {
this.name = name;
this.gpa = gpa;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
}Accessors and mutators
An accessor (getter) returns the value of a private field. It does not change anything. Example: public double getGpa() { return gpa; }
A mutator (setter) changes the value of a private field. Example: public void setGpa(double gpa) { this.gpa = gpa; }
Accessors are "get" functions. Mutators are "set" functions. Do not mix these up.
Access specifiers
private: accessible only within the same class. Used for member variables to enforce data hiding.
public: accessible from any class. Used for constructors, getters and setters.
protected: accessible within the same class and its subclasses (less common at this level).
There is no global access specifier in Java.
The dot operator
Used to access public members of an object from outside the class: s1.getGpa(), s1.setGpa(3.9).
The scope resolution operator (::) is a C++ concept, not used in Java for member access.
Destructors (C++ context)
In C++, a destructor is called when an object is destroyed. Its name is the tilde (~) followed by the class name: ~Student().
Java does not have explicit destructors; it uses garbage collection instead.
This topic appears on the CSE110 exam as an OOP fundamentals concept, even though the course is Java-focused.
Students think defining a class creates an object. It does not. A class is a blueprint. An object is created only when you instantiate it with new.
Students think constructors have a return type of void. Constructors have no return type at all.
Students confuse accessors and mutators. Accessors are "get" functions (they read a value). Mutators are "set" functions (they change a value).
Students assume a class can only have one constructor. Classes can have multiple constructors through overloading, as long as parameter lists differ.
Students think private variables can be accessed from other classes. They cannot. That is the entire point of marking them private.
ADT definition (Q11, Q43): know that it specifies values and operations while hiding implementation details.
Encapsulation (Q12, Q44): bundling data and methods into a single unit. This is the most-tested OOP concept at this level.
Constructor return type (Q13): the answer is "no return type", not void.
Destructor prefix (Q14): tilde (~), tested as a C++ crossover concept.
Accessor vs mutator (Q15, Q29): know which is get and which is set.
Access specifiers (Q16, Q19, Q37): private for data hiding, public for interface, dot operator for access.
Class vs object (Q27, Q28): a class declaration does not create an object; a constructor is called automatically when an object is created.
Multiple constructors (Q36, Q39, Q48): a class can have more than one; default takes no args, overloaded takes args.
The Student class (Q51): be able to write a complete class with private fields, a constructor, a getter and a setter.
True or false: A class declaration creates an object in memory. Answer: False. You must instantiate it with new.
What is the return type of a constructor? Answer: None. Constructors have no return type.
True or false: Accessor functions are also known as "set" functions. Answer: False. Accessors are "get" functions.
What character does a C++ destructor name begin with? Answer: Tilde (~).
True or false: A class can have only one constructor. Answer: False. A class can have multiple constructors through overloading.
Q: What does ADT stand for, and what does it mean?
A: Abstract Data Type. It specifies the values a type can hold and the operations it can perform, while hiding how those operations are implemented.
Q: Define encapsulation in the context of OOP.
A: Encapsulation is the principle of bundling data (attributes) and the methods that operate on that data into a single unit (class), while restricting direct access to the internal data through access specifiers like private.
Q: What access specifier is typically used for an object's internal data to enforce data hiding?
A: private.
Q: Which operator is used to access public members of an object from outside the class?
A: The dot operator (.).
Q: Distinguish between a default constructor and an overloaded constructor.
A: A default constructor takes no parameters and provides standard initialisation. An overloaded constructor accepts parameters, allowing custom initialisation of the object's fields.
Q: Write the complete class definition for a Student class with private name (String) and gpa (double) fields, a constructor accepting both, and a public getter and setter for gpa.
A:
public class Student {
private String name;
private double gpa;
public Student(String name, double gpa) {
this.name = name;
this.gpa = gpa;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
}OOP builds directly on functions (Chapter 6): every method in a class is a function. The concepts of parameters, return types and overloading apply identically. Encapsulation connects to the idea of scope from Chapter 6, since private is essentially a stricter form of local scope. Arrays of objects (creating an array where each element is an instance of a class) bridge Chapters 7 and 8.
CSE110 OOP, object-oriented programming Java, class vs object, abstract data type ADT, encapsulation Java, data hiding private, constructor no return type, default constructor, overloaded constructor, destructor tilde C++, accessor getter, mutator setter, get method set method, access specifier private public, dot operator Java, ASU CSE110 Chapter 7, Principles of Programming OOP