You are on page 1of 3

oops concepts-

String-
Collection Framework-
Exception handling-

object oriented programming's-

Encapsulation
Inheritance
Polymorphism
Abstraction---
----------------------------------------------
Abstraction-
it is process of hiding some details and showing important thing to end user
called.

Live example-

1. Car- focus out on color, size, brand, model no, seating capacity-

hiding some details means- dont know how the engine system works,
how gear system works , how sound system works

2. TV Remote-

3. ATM Screen- card-insert-internally dont know what will happen-

how to achieve abstraction in java?

Abstract class
Interface
-------------------------
Abstract class-

1. have constructor-- with the help of Dcompiler


2. contain abstract and concrete method or both or empty
3. cant create object of abstract class.--- why?
4. if we want to use abstract method, need to extend abstract class
5. if we dont want to override or implement method, class--->abstract
6. if any method is abstract in class then make that class as abstract
7. we can write n no of abstract in abstract class

---create class--->define abstract method---->make class as abstract--->

----create one class as Implementation---> extends Abstract class(Name)--->

Error--> mouse pointer-->Add unimplemented method--click on it.

---------------------------------------------------------------
Interface-
- dont have constructor
- contain
method- public abstract by default
variable- public static final by default
- cant create the object of interface.
- Define interface-- method declare only ---->class-->implements- 1.7 java version
- I to C design principle- every class is implemented by some interfaces.
- 1.8 onwards- we write method with body interface-
- suppose if I dont want to implement or override the method then
what will you do ? make class as abstract

How to create or design interface

syntax- interface interface_name {

Note- Multple inheritance is supported in java in case of interface but not classes

Scenario based-

Interface A{

void x2 ();
}

Interface B{

void x2();
}

class XYZ implements A,B{

total how many method will be implemented?

only one method will be override- which one interface ?

---------------------industry use-----------------------------
class Employee{

void getEmployeeInfo(){
//logic
}

in company,

Interface Employee{

void getEmployeeInfo();

class EmployeeImpl implements Employee{

@Override
void getEmployeeInfo(){
//logic

}
}
-------------------------------------------------
when to use abstract class and interface

abstract class- some of implementation we know and some of implementation we


dont know--

Example- fixedDeposit() -----simpleInterest()----diff-

int fixedDeposit(int amt){


//logic
}

float simpleInterest(float rate){

Interface- if we dont know anything about the implementation

Student---> Add, update, delete, get operation-

we dont know what is logic inside perticular method

You might also like