Learn programming concepts interactively
Objects are fundamental building blocks in programming that mirror real-world entities. Just like real-world objects, software objects have state (properties/attributes) andbehavior (methods/functions).
This interactive page lets you explore different software objects, see their internal state, and trigger their behaviors.
Internal state is hidden (Encapsulation).
/*** Bicycle class demonstrating OOP concepts* State: Properties that define the object's current condition* Behavior: Methods that can modify the object's state*/public class Bicycle {// State (Properties) - Private fields for encapsulationprivate int currentSpeed;private int currentGear;private int pedalCadence;private boolean isMoving;// Constructor - Initialize object statepublic Bicycle() {this.currentSpeed = 0;this.currentGear = 1;this.pedalCadence = 0;this.isMoving = false;}// Behavior (Methods) - Actions the object can perform// Getters - Controlled access to private statepublic int getCurrentSpeed() {return this.currentSpeed;}public int getCurrentGear() {return this.currentGear;}public int getPedalCadence() {return this.pedalCadence;}public boolean getIsMoving() {return this.isMoving;}// Main method for testingpublic static void main(String[] args) {Bicycle myBicycle = new Bicycle() ;System.out.println("Created a new Bicycle!");// Demonstrate object behavior}}
No operations yet
Start by adding or modifying elements