SlideShare a Scribd company logo
Object Oriented Programming with Java
(Subject Code: BCS-403)
Unit 1
Lecture 10
Lecture 10
• Abstraction
• Interfaces
• Abstract Class
Abstraction in Java
Abstraction is a process of hiding the
implementation details and showing only
functionality to the user.
Example to understand Abstraction:
Television remote control is an excellent example of
abstraction. It simplifies the interaction with a TV by
hiding the complexity behind simple buttons and
symbols, making it easy without needing to understand
the technical details of how the TV functions.
Ad
Abstract class in Java
• A class that is declared with abstract keyword,
is known as abstract class in java. It can have
abstract and non-abstract methods (method
with body).
Ways to achieve Abstaction
There are two ways to achieve abstraction in
java
• Abstract class (0 to 100%)
• Interface (100%)
Abstract class in Java
• A class that is declared as abstract is known
as abstract class. It needs to be extended and its
method implemented. It cannot be instantiated.
Example
abstract class A{}
Abstract method
• A method that is declared as abstract and does
not have implementation is known as abstract
method.
Example
abstract void printStatus();//no body and abstract
Ad
Lecture-on-Object-Oriented-Programming-Language-Java.pptx
Example of abstract class that has abstract method
In this example, Bike the abstract class that contains only one
abstract method run. It implementation is provided by the
Honda class.
abstract class Bike{
abstract void run();
}
class Honda4 extends Bike{
void run(){System.out.println("running safely..");}
public static void main(String args[]){
Honda4 obj = new Honda4();
obj.run();
}
}
Ad
abstract class Bank{
abstract double getRateOfInterest();
}
class SBI extends Bank{
double getRateOfInterest(){return 7.5;}
}
class PNB extends Bank{
double getRateOfInterest(){return 7;}
}
class TestBank{
public static void main(String args[]){
SBI b=new SBI();//if object is PNB, method of PNB will be invoked
int interest=b.getRateOfInterest();
System.out.println("Rate of Interest is: "+interest+" %");
}}
• Rate of Interest is: 7.5 %
An abstract class can have data member, abstract method, method body,
constructor and even main() method.
File: TestAbstraction2.java
//example of abstract class that have method body
abstract class Bike{
Bike(){System.out.println("bike is created");}
abstract void run();
void changeGear(){System.out.println("gear changed");}
}
class Honda extends Bike{
void run(){System.out.println("running safely..");}
}
class TestAbstraction2{
public static void main(String args[]){
Bike obj = new Honda();
obj.run();
obj.changeGear();
} }
Ad
• Rule: If you are extending any abstract class
that have abstract method, you must either
provide the implementation of the method
or make this class abstract.
• Rule: If there is any abstract method in a
class, that class must be abstract.
The abstract class can also be used to provide some
implementation of the interface. In such case, the end user
may not be forced to override all the methods of the
interface.
interface A{
void a();
void b();
void c();
void d();
}
abstract class B implements A{
public void c(){System.out.println("I am C");}
}
Ad
class M extends B{
public void a(){System.out.println("I am a");}
public void b(){System.out.println("I am b");}
public void d(){System.out.println("I am d");}
}
class Test5{
public static void main(String args[]){
M a=new M();
a.a();
a.b();
a.c();
a.d();
}}
Interface in Java
• An interface in java is a blueprint of a class. It has
static constants and abstract methods only.
• The interface in java is a mechanism to achieve
fully abstraction. There can be only abstract
methods in the java interface not method body. It
is used to achieve fully abstraction and multiple
inheritance in Java.
• Java Interface also represents IS-A relationship.
• It cannot be instantiated just like abstract class.
Ad
Why use Java interface?
There are mainly three reasons to use interface. They
are given below.
• It is used to achieve fully abstraction.
• By interface, we can support the functionality of
multiple inheritance.
• It can be used to achieve loose coupling.
The java compiler adds public and abstract keywords
before the interface method and public, static and
final keywords before data members.
In other words, Interface fields are public, static and
final by default, and methods are public and abstract.
Lecture-on-Object-Oriented-Programming-Language-Java.pptx
Ad
interface printable{
void print();
}
class A6 implements printable{
public void print(){System.out.println("Hello");}
public static void main(String args[]){
A6 obj = new A6();
obj.print();
}
}
Multiple inheritance in Java by interface
• If a class implements multiple interfaces, or an
interface extends multiple interfaces i.e.
known as multiple inheritance.
Ad
Lecture-on-Object-Oriented-Programming-Language-Java.pptx
interface Printable{
void print();
}
interface Showable{
void show();
}
class A7 implements Printable,Showable{
public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}
public static void main(String args[]){
A7 obj = new A7();
obj.print();
obj.show();
}
}
Ad
Interface inheritance
A class implements interface but one interface extends another interface .
interface Printable{
void print();
}
interface Showable extends Printable{
void show();
}
class Testinterface2 implements Showable{
public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}
public static void main(String args[]){
Testinterface2 obj = new Testinterface2();
obj.print();
obj.show();
} }
Lecture-on-Object-Oriented-Programming-Language-Java.pptx
Ad
Ad

More Related Content

Similar to Lecture-on-Object-Oriented-Programming-Language-Java.pptx (20)

PDF
Exception handling and packages.pdf
74 slides75 views
PPTX
Session 10 - OOP with Java - Abstract Classes and Interfaces
22 slides99 views
PPTX
A class which is declared with the abstract keyword is known as an abstract c...
11 slides32 views
PPTX
abstract,final,interface (1).pptx upload
42 slides44 views
PDF
21UCAC31 Java Programming.pdf(MTNC)(BCA)
34 slides29 views
PPTX
Objects and classes in OO Programming concepts
27 slides19 views
PDF
Basic_Java_10.pdf
29 slides145 views
PPTX
OOFeatures_revised-2.pptx
56 slides35 views
PDF
Core Java Interface Concepts for BCA Studetns
5 slides26 views
PPTX
Abstract class
7 slides88 views
PPTX
ITTutor Advanced Java (1).pptx
87 slides29 views
PDF
Abstraction in Java: Abstract class and Interfaces
19 slides279 views
PPTX
Interface in java ,multiple inheritance in java, interface implementation
11 slides2K views
PPTX
Interface in java
16 slides456 views
PDF
How to Work with Java Interfaces and Abstract Classes
12 slides11 views
PDF
OOPs Concepts - Android Programming
29 slides4.6K views
PDF
11.Object Oriented Programming.pdf
25 slides113 views
PPTX
Abstract class and interface
25 slides328 views
DOCX
java_training_report_collage_summer_holiday_homework.docx
63 slides11 views
PPTX
Java Interface
9 slides160 views
Exception handling and packages.pdf
74 slides75 views
Session 10 - OOP with Java - Abstract Classes and Interfaces
22 slides99 views
A class which is declared with the abstract keyword is known as an abstract c...
11 slides32 views
abstract,final,interface (1).pptx upload
42 slides44 views
21UCAC31 Java Programming.pdf(MTNC)(BCA)
34 slides29 views
Objects and classes in OO Programming concepts
27 slides19 views
Basic_Java_10.pdf
29 slides145 views
OOFeatures_revised-2.pptx
56 slides35 views
Core Java Interface Concepts for BCA Studetns
5 slides26 views
Abstract class
7 slides88 views
ITTutor Advanced Java (1).pptx
87 slides29 views
Abstraction in Java: Abstract class and Interfaces
19 slides279 views
Interface in java ,multiple inheritance in java, interface implementation
11 slides2K views
Interface in java
16 slides456 views
How to Work with Java Interfaces and Abstract Classes
12 slides11 views
OOPs Concepts - Android Programming
29 slides4.6K views
11.Object Oriented Programming.pdf
25 slides113 views
Abstract class and interface
25 slides328 views
java_training_report_collage_summer_holiday_homework.docx
63 slides11 views
Java Interface
9 slides160 views

Recently uploaded (20)

PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
20 slides106 views
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
60 slides352 views
PPTX
Safety Seminar civil to be ensured for safe working.
94 slides176 views
PPTX
UNIT 4 Total Quality Management .pptx
58 slides276 views
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
51 slides315 views
PPTX
additive manufacturing of ss316l using mig welding
36 slides182 views
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
17 slides157 views
PPT
introduction to datamining and warehousing
41 slides101 views
PDF
PPT on Performance Review to get promotions
43 slides248 views
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
22 slides119 views
PPTX
Current and future trends in Computer Vision.pptx
47 slides236 views
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
189 slides350 views
PPTX
Geodesy 1.pptx...............................................
63 slides328 views
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
93 slides314 views
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
15 slides225 views
PPTX
Fundamentals of Mechanical Engineering.pptx
110 slides111 views
PPTX
Sustainable Sites - Green Building Construction
41 slides196 views
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
21 slides152 views
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
103 slides182 views
PPTX
Internet of Things (IOT) - A guide to understanding
31 slides277 views
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
20 slides106 views
Automation-in-Manufacturing-Chapter-Introduction.pdf
60 slides352 views
Safety Seminar civil to be ensured for safe working.
94 slides176 views
UNIT 4 Total Quality Management .pptx
58 slides276 views
CYBER-CRIMES AND SECURITY A guide to understanding
51 slides315 views
additive manufacturing of ss316l using mig welding
36 slides182 views
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
17 slides157 views
introduction to datamining and warehousing
41 slides101 views
PPT on Performance Review to get promotions
43 slides248 views
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
22 slides119 views
Current and future trends in Computer Vision.pptx
47 slides236 views
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
189 slides350 views
Geodesy 1.pptx...............................................
63 slides328 views
UNIT-1 - COAL BASED THERMAL POWER PLANTS
93 slides314 views
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
15 slides225 views
Fundamentals of Mechanical Engineering.pptx
110 slides111 views
Sustainable Sites - Green Building Construction
41 slides196 views
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
21 slides152 views
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
103 slides182 views
Internet of Things (IOT) - A guide to understanding
31 slides277 views
Ad

Lecture-on-Object-Oriented-Programming-Language-Java.pptx

  • 1. Object Oriented Programming with Java (Subject Code: BCS-403) Unit 1 Lecture 10
  • 2. Lecture 10 • Abstraction • Interfaces • Abstract Class
  • 3. Abstraction in Java Abstraction is a process of hiding the implementation details and showing only functionality to the user. Example to understand Abstraction: Television remote control is an excellent example of abstraction. It simplifies the interaction with a TV by hiding the complexity behind simple buttons and symbols, making it easy without needing to understand the technical details of how the TV functions.
  • 4. Abstract class in Java • A class that is declared with abstract keyword, is known as abstract class in java. It can have abstract and non-abstract methods (method with body). Ways to achieve Abstaction There are two ways to achieve abstraction in java • Abstract class (0 to 100%) • Interface (100%)
  • 5. Abstract class in Java • A class that is declared as abstract is known as abstract class. It needs to be extended and its method implemented. It cannot be instantiated. Example abstract class A{} Abstract method • A method that is declared as abstract and does not have implementation is known as abstract method. Example abstract void printStatus();//no body and abstract
  • 7. Example of abstract class that has abstract method In this example, Bike the abstract class that contains only one abstract method run. It implementation is provided by the Honda class. abstract class Bike{ abstract void run(); } class Honda4 extends Bike{ void run(){System.out.println("running safely..");} public static void main(String args[]){ Honda4 obj = new Honda4(); obj.run(); } }
  • 8. abstract class Bank{ abstract double getRateOfInterest(); } class SBI extends Bank{ double getRateOfInterest(){return 7.5;} } class PNB extends Bank{ double getRateOfInterest(){return 7;} } class TestBank{ public static void main(String args[]){ SBI b=new SBI();//if object is PNB, method of PNB will be invoked int interest=b.getRateOfInterest(); System.out.println("Rate of Interest is: "+interest+" %"); }} • Rate of Interest is: 7.5 %
  • 9. An abstract class can have data member, abstract method, method body, constructor and even main() method. File: TestAbstraction2.java //example of abstract class that have method body abstract class Bike{ Bike(){System.out.println("bike is created");} abstract void run(); void changeGear(){System.out.println("gear changed");} } class Honda extends Bike{ void run(){System.out.println("running safely..");} } class TestAbstraction2{ public static void main(String args[]){ Bike obj = new Honda(); obj.run(); obj.changeGear(); } }
  • 10. • Rule: If you are extending any abstract class that have abstract method, you must either provide the implementation of the method or make this class abstract. • Rule: If there is any abstract method in a class, that class must be abstract.
  • 11. The abstract class can also be used to provide some implementation of the interface. In such case, the end user may not be forced to override all the methods of the interface. interface A{ void a(); void b(); void c(); void d(); } abstract class B implements A{ public void c(){System.out.println("I am C");} }
  • 12. class M extends B{ public void a(){System.out.println("I am a");} public void b(){System.out.println("I am b");} public void d(){System.out.println("I am d");} } class Test5{ public static void main(String args[]){ M a=new M(); a.a(); a.b(); a.c(); a.d(); }}
  • 13. Interface in Java • An interface in java is a blueprint of a class. It has static constants and abstract methods only. • The interface in java is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java. • Java Interface also represents IS-A relationship. • It cannot be instantiated just like abstract class.
  • 14. Why use Java interface? There are mainly three reasons to use interface. They are given below. • It is used to achieve fully abstraction. • By interface, we can support the functionality of multiple inheritance. • It can be used to achieve loose coupling. The java compiler adds public and abstract keywords before the interface method and public, static and final keywords before data members. In other words, Interface fields are public, static and final by default, and methods are public and abstract.
  • 16. interface printable{ void print(); } class A6 implements printable{ public void print(){System.out.println("Hello");} public static void main(String args[]){ A6 obj = new A6(); obj.print(); } }
  • 17. Multiple inheritance in Java by interface • If a class implements multiple interfaces, or an interface extends multiple interfaces i.e. known as multiple inheritance.
  • 19. interface Printable{ void print(); } interface Showable{ void show(); } class A7 implements Printable,Showable{ public void print(){System.out.println("Hello");} public void show(){System.out.println("Welcome");} public static void main(String args[]){ A7 obj = new A7(); obj.print(); obj.show(); } }
  • 20. Interface inheritance A class implements interface but one interface extends another interface . interface Printable{ void print(); } interface Showable extends Printable{ void show(); } class Testinterface2 implements Showable{ public void print(){System.out.println("Hello");} public void show(){System.out.println("Welcome");} public static void main(String args[]){ Testinterface2 obj = new Testinterface2(); obj.print(); obj.show(); } }