class classname { // Variable Declarations // Method definitions }
classname objectName = new constructorname();
// Example: Classes and Objects class Bike { // variable declaration String model; String brand; // Method to assign the bike details(Without parameter) public void assignBikeDetails() { model = "CT-100"; brand = "Bajaj"; } // Method to assign the bike details (With parameter) public void assgnBikeDetails1(String m, String b){ model = m; brand = b; }// Method to display the Bike details public void showBikeDetails() { System.out.println("Model = " + model); System.out.println("Brand = " + brand); }} // End of the class definition// Implementation classclass ClassDemo { public static void Main() { // Object Creation Bike objBike; // Object Initialization objBike = new Bike(); // Invoking the Method without parameter objBike.assgnBikeDetails(); objBike.showBikeDetails(); // Object Creation and Initialization Bike objBike1 = new Bike(); // Invoking the Method with parameter objBike1.assgnBikeDetails1("Splendor", "Hero-Honda"); objBike1.showBikeDetails(); }}