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