Classes, Objects, Fields & Methods
Design classes and instantiate objects in Java, define instance fields and methods, and understand parameter passing and return types.
- (blueprints) and objects (runtime instances on the Heap). A class defines state (fields) and behavior (methods).
- an object does while hiding how it does it.
- stored in local variable
con the Stack. - is copied—so a method can mutate the object's fields, but reassigning the parameter variable does not affect the caller's reference.
Introduction
Object-Oriented Programming (OOP) organizes complex software into cohesive classes (blueprints) and objects (runtime instances on the Heap). A class defines state (fields) and behavior (methods).
Four Pillars of OOP
- 1Encapsulation: Protecting internal state behind validated methods.
- 2Inheritance: Reusing and specializing behavior from a parent class.
- 3Polymorphism: Treating different concrete types uniformly through a shared interface or base class.
- 4Abstraction: Exposing what an object does while hiding how it does it.
Object Creation & Pass-by-Value in Java
When you write Course c = new Course();, the new operator allocates memory on the Heap, initializes fields, runs the constructor, and returns a reference stored in local variable c on the Stack. Java is strictly pass-by-value: for primitives, the value is copied; for object references, the reference address is copied—so a method can mutate the object's fields, but reassigning the parameter variable does not affect the caller's reference.
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)