Oops Concepts
Oops Concepts
I MCA
JAVA CLASS
• A class is a blueprint for the object. Before we create an object, we
first need to define the class.
• Since many houses can be made from the same description, we can
create many objects from a class.
Create a class in Java
An interface is a completely "abstract class" that is used to group related methods with empty
bodies:
To access the interface methods, the interface must be "implemented" ( like inherited) by
another class with the implements keyword (instead of extends).
The body of the interface method is provided by the "implement" class:
EXAMPLE
// Interface
interface Animal { class Main {
public void animalSound(); // interface method (does not have a public static void main(String[] args) {
body) Pig myPig = new Pig(); // Create a Pig object
myPig.animalSound();
public void sleep(); // interface method (does not have a body)
myPig.sleep();
} }
// Pig "implements" the Animal interface }
class Pig implements Animal {
public void animalSound() { The pig says: wee wee
// The body of animalSound() is provided here Zzz
class Vehicle {
protected String brand = "Ford";
public void honk() {
System.out.println("Tuut, tuut!");
}
}