OOP
Class
public class Person {
// Attributes (instance variables)
String name;
int age;
// Constructor
public Person(String name, int age) {
this.name = name;
this.age = age;
}
// Method
public void introduce() {
System.out.println("Hello, I'm " + name + " and I'm " + age + " years old.");
}
}Object
Interface
Class implements Interface
4 fundamental principles of OOP
Inheritence
Polymorphism
Encapsulation
Abstraction
Last updated