java oop

public static void main(String[] args) { { System.out.println(“Summer”); } } { System.out.println(“Winter”); } 1 public class Car { 2 private String model = “Ford”; 3 4 { 5 System.out.println(“Instance Initializer block…”); 6 } 7 8 public Car () { 9 model = “Opel”; 10 System.out.println(“Constructor…”); 11 } 12 13 public static void main(String[] args) {…

Read More Java Instance Initializer Block

class Vehicle { void startEngine() { System.out.println(“Starting the engine…”); } void stopEngine() { System.out.println(“Stopping the engine…”); } } class Car extends Vehicle { void move() { System.out.println(“The car is moving…”); } void invoke() { super.startEngine(); move(); super.stopEngine(); } } class TestSuper2 { public static void main(String args[]){ Car car = new Car(); car.invoke(); } }…

Read More Keyword super in Java

class Car { public static String MODEL = “Ford”; } public class ConstructorExample { public static void main(String[] args) { System.out.println(Car.MODEL); } } Output: Ford Static methods class Car { public static String MODEL = “Ford”; public static void printModel() { System.out.println(“Model is: ” + MODEL); } } Output: Model is: Ford   Read more…

Read More Keyword static in Java

nameOfTheClass() {} class Car { public Car() { // constructor System.out.println(“The car is mooving!”); } public static void main(String args[]) { Car car = new Car(); // with this, we are actually calling a constructor } } Output: The car is moving!   Note: The compiler automatically creates a default constructor if there is no constructor…

Read More Constructor in Java

By following these naming conventions, your code will be consistent and easy to read, making it easier to collaborate with other developers and maintain your code over time. CamelCase in Java CamelCase is a naming convention that is commonly used in Java for naming variables, methods, and classes. It involves writing the first letter of…

Read More Mastering Java Naming Conventions for Superior Code