Java Program of Simple Class and Object.

 
public class SimpleClassExample {
    public static void main(String[] args) {
        // Create an object of the SimpleClass
        SimpleClass myObject = new SimpleClass();

        // Access the object's variables and methods
        myObject.name = "John";
        myObject.age = 25;
        myObject.displayInfo();
    }
}

class SimpleClass {
    // Instance variables
    String name;
    int age;

    // Method to display information
    public void displayInfo() {
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
    }
}


Java program to print the object

 
class Hello {

}

class Main {
  public static void main(String[] args) {

    // create an object of the Hello class
   Hello obj = new Hello();

    
    System.out.println(obj);
  }
}

Java Program To represent the concept of all types of inheritance supported by Java, design a program.

 
// Base class
class Vehicle {
    protected String brand;

    public Vehicle(String brand) {
        this.brand = brand;
    }

    public void displayInfo() {
        System.out.println("Brand: " + brand);
    }
}

// Derived class inheriting from Vehicle
// (Single Inheritance)
class Car extends Vehicle {
    private int numOfDoors;

    public Car(String brand, int numOfDoors) {
        super(brand);
        this.numOfDoors = numOfDoors;
    }

    public void displayCarInfo() {
        displayInfo();
        System.out.println("Number of Doors: " + numOfDoors);
    }
}

// Derived class inheriting from Car 
//(Multilevel Inheritance)
class SportsCar extends Car {
    public SportsCar(String brand, int numOfDoors) {
        super(brand, numOfDoors);
    }

    public void displaySportsCarInfo() {
        displayCarInfo();
    }
}

// Derived class implementing an interface
// (Interface Inheritance)
interface Flyable {
    void fly();
}

class Airplane implements Flyable {
    public void fly() {
        System.out.println("Airplane is flying");
    }
}

public class InheritanceExample {
    public static void main(String[] args) {
        // Single Inheritance
        Car car = new Car("Toyota", 4);
        car.displayCarInfo();
        System.out.println();

        // Multilevel Inheritance
        SportsCar sportsCar = new SportsCar("Ferrari", 2);
        sportsCar.displaySportsCarInfo();
        System.out.println();

        // Interface Inheritance
        Airplane airplane = new Airplane();
        airplane.fly();
    }
}

Java Program with Static Variables and Methods

 
public class StaticExample {
    // Static variable
    static int count = 0;

    // Static method
    public static void incrementCount() {
        count++;
    }

    public static void main(String[] args) {
        // Access static variable and method using class name
        System.out.println("Initial count: " + StaticExample.count);
        StaticExample.incrementCount();
        System.out.println("Updated count: " + StaticExample.count);
    }
}

Java Program to define Constructors and Method Overloading

 
public class SimpleClass {
    private int number;
    private String text;

    // Default constructor
    public SimpleClass() {
        number = 0;
        text = "Default Text";
    }

    // Constructor with parameters
    public SimpleClass(int num, String txt) {
        number = num;
        text = txt;
    }



    // Method with no parameters
    public void displayInfo() {
        System.out.println("Number: " + number);
        System.out.println("Text: " + text);
    }

    // Method with one parameter (method overloading)
    public void displayInfo(String course) {
        System.out.println("Number: " + number);
        System.out.println("Text: " + text);
        System.out.println("course: " + course);
    }

    public static void main(String[] args) {
        // Using default constructor
        SimpleClass obj1 = new SimpleClass();
        obj1.displayInfo();
        System.out.println();

        // Using constructor with parameters
        SimpleClass obj2 = new SimpleClass(10, "jpnotes");
        obj2.displayInfo();
        System.out.println();

        // Using method overloading
        obj2.displayInfo("course");
    }
}

Java Program to Create an wrapper classes.

 
public class WrapperClassExample {
    public static void main(String[] args) {
        // Wrapper classes for primitive types
        Integer myInt = 10;
        Double myDouble = 3.14;
        Character myChar = 'A';
        Boolean myBoolean = true;

        // Printing values
        System.out.println("Wrapper Classes:");
        System.out.println("Integer: " + myInt);
        System.out.println("Double: " + myDouble);
        System.out.println("Character: " + myChar);
        System.out.println("Boolean: " + myBoolean);
    }
}

Java Program to Create an final class.

 
final class FinalClass {
    // Class implementation
    // ...
}

public class Main {
    public static void main(String[] args) {
        // Create an object of the final class
        FinalClass obj = new FinalClass();
        // Access and use the object
        // ...
    }
}

Java Program to Create an abstract class.

 
abstract class AbstractClass {
    public abstract void display();
}

public class Main {
    public static void main(String[] args) {
        
        Classxyz obj = new Classxyz();
        // Call the abstract method
        obj.display();
    }
}

class Classxyz extends AbstractClass {
   
    public void display() {
        System.out.println("Abstract method implementation");
    }
}
index