Professional Documents
Culture Documents
Handout4-ReviewJavaBasis-OCA Java SE 8 Programmer I
Handout4-ReviewJavaBasis-OCA Java SE 8 Programmer I
• Object • Polymorphism
• Class • Abstraction
• Inheritance • Encapsulation
An Object can be defined as an instance of a class. Class: Collection of objects is called class. It is a
An object contains an address and takes up some logical entity.
A class can also be defined as a blueprint from member is private it means it can only be accessed
which you can create an individual object. Class within the same class. No outside class can access
doesn't consume any space. private data member (variable) of other class.
It’s quite difficult to understand the concept of
Inheritance: When one object acquires all the encapsulation from a \. So let’s understand what
properties and behaviors of a parent object, it is encapsulation is by looking at some code examples.
known as inheritance. It provides code reusability. class Person {
It is used to achieve runtime polymorphism. String name;
int age;
Polymorphism void talk() {
If one task is performed by different ways, it is }
known as polymorphism. For example: to convince void think() {
the customer differently, to draw something, for }
example, shape, triangle, rectangle, etc. void work() {
}
In Java, we use method overloading and method void play() {
overriding to achieve polymorphism. }
}
Another example can be to speak something; for Here, the common characteristics and behaviors of
example, a cat speaks meow, dog barks woof, etc. a person are packaged into a single unit: the Person
class. This is the process of encapsulation
Encapsulation is also known as “data Hiding”.
Abstraction
Hiding internal details and showing functionality is
known as abstraction. For example phone call, we
don't know the internal processing.
In Java, we use abstract class and interface to
achieve abstraction.