Object-Oriented Programming in Java

 Object-Oriented Programming in Java


Java is an object-oriented programming language, which means that you can define classes to encapsulate data and behavior. You can then create objects from these classes to interact with your program.


Example code:


csharp


public class Person {

    private String name;

    private int age;


    public Person(String name, int age) {

        this.name = name;

        this.age = age;

    }


    public String getName() {

        return name;

    }


    public int getAge() {

        return age;

    }

}


Person john = new Person("John", 25);

System.out.println(john.getName()); // prints "John"

System.out.println(john.getAge()); // prints 25

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...