You are on page 1of 1

OOPS:

Inheritance: "It is a very important concept in OOPs.


It is a characters inheritate by the child class from parent class."
It helps to reuse the code and establish the relationship
between differant classes.

Encapsulation: "Mechanism of binding data and code


together in a single unit".
It also means to hide your data in order to make
it safe from any modification. Through encapsulation methods and
variables of a class are well hidden and safe.

**We can achieve encapsulation in Java by:

**Declaring the variables of a class as private.


**Providing public setter and getter methods to
modify and view the variables values.

public class Employee {


private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static void main(String[] args) {
}
}

You might also like