OOP Foundations - Reference Handout
What You'll Learn Today
Today we'll dive deep into Object-Oriented Programming (OOP) fundamentals in Java. You'll learn how to create well-structured classes, work with different types of constructors, and understand how to properly organize your code using access modifiers.
Key Concepts
Classes and Objects
- Class structure and components
- Creating objects (instantiation)
- The
this
keyword - Object state and behavior
Constructors
- Default constructors
- Parameterized constructors
- Constructor overloading
- Constructor chaining
Instance vs Static
- Instance variables and methods
- Static variables and methods
- When to use each
- The
static
keyword
Access Modifiers & Encapsulation
- Public, private, protected
- Package-level access
- Getter and setter methods
- Encapsulation principles
Practice Exercises
Exercise 1: Building a Student Class
Create a Student
class with:
- Private fields for name, ID, and grades
- Multiple constructors
- Getter/setter methods
- A method to calculate average grade
Exercise 2: Static Members
Create a School
class with:
- Static counter for total students
- Instance fields for school details
- Methods that use both static and instance members
Exercise 3: Class Hierarchies
Design classes for a simple library system: - Base class for library items - Specific classes for books, magazines, etc. - Proper use of access modifiers
Additional Resources
- Java Documentation on Classes and Objects
- Online Java Visualizer tools
- Practice problems and solutions
- Recommended reading materials
Notes
- Ask questions whenever you need clarification
- Take breaks when needed
- Focus on understanding concepts over memorizing syntax
- Keep your code organized and well-documented