Core Concepts of Object-Oriented Programming (OOP)

Class and Object (Instance) A class is a blueprint for creating objects; an object is an instance of that blueprint. A circle requires a center point and a radius, which become the Circle class’s data fields. The center point is modeled as a Point class encapsulating x and y coordinates. Access Modifiers (public, private, package-default, protected) private: Members are accessible only within their class. Instance variables should be private to maintain data integrity (bank account analogy). public: Members are accessible from any class. Common for methods (like getters) that expose controlled access to private data. The main method must be public for the Java runtime to invoke it. package (default): If no modifier is specified, the member is accessible only within the same package. (BTW, don’t include package declarations from some IDEs when submitting to OJ.) protected: Mentioned in the context of inheritance (will be covered in a future lecture). Members are accessible to subclasses. Method Overriding vs. Overloading ...

2025-10-30 · 5 min · 873 words · ssdxx