Have a question?
Message sent Close
View Categories

Non Primitive Data Types

Non Primitive Data Types

📄
filename.js
public class Main {

    public static void main(String[] args) {

        String greeting = "Hello, World!";

        System.out.println(greeting);  // Output: Hello, World!

    }

}
📄
filename.js
public class Main {

    public static void main(String[] args) {

        int[] numbers = {1, 2, 3, 4, 5};

        for (int num : numbers) {

            System.out.print(num + " ");  // Output: 1 2 3 4 5

        }

    }

}
📄
filename.js
public class Main {

    public static void main(String[] args) {

        Person person = new Person("Alice", 30);

        person.displayInfo();  // Output: Name: Alice, Age: 30

    }

}

class Person {

    String name;

    int age;

    Person(String name, int age) {

        this.name = name;

        this.age = age;

    }

    void displayInfo() {

        System.out.println("Name: " + name + ", Age: " + age);

    }

}
📄
filename.js
public class Main {

    public static void main(String[] args) {

        Dog dog = new Dog();

        dog.makeSound();  // Output: Bark

    }

}

interface Animal {

    void makeSound();

}

class Dog implements Animal {

    public void makeSound() {

        System.out.println("Bark");

    }

}
📄
filename.js
public class Main {

    public static void main(String[] args) {

        Day day = Day.MONDAY;

        System.out.println(day);  // Output: MONDAY

    }

}

enum Day {

    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY

}