SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
ABSTRACT CLASSES AND METHODS
Abstract class in Java
• A class which is declared with the abstract keyword is known as
an abstract class in Java. It can have abstract and non-abstract
methods (method with the body).
Abstraction in Java
• Abstraction is a process of hiding the implementation details and
showing only functionality to the user.
• Another way, it shows only essential things to the user and hides
the internal details. Abstraction lets you focus on what
the object does instead of how it does it.
• There are two ways to achieve abstraction in java
✔ Abstract class (0 to 100%)
✔ Interface (100%)
Abstract class in Java
• A class which is declared as abstract is known as an abstract class.
It can have abstract and non-abstract methods. It needs to be
extended and its method implemented. It cannot be instantiated.
• Points to Remember
• An abstract class must be declared with an abstract keyword.
• It can have abstract and non-abstract methods.
• It cannot be instantiated.
• It can have constructors and static methods also.
• It can have final methods which will force the subclass not to
change the body of the method.
Example of abstract class
abstract class A{}
Abstract Method in Java
• A method which is declared as abstract and does not have
implementation is known as an abstract method.
Example of abstract method
abstract void printStatus();//no method body and abst
ract
Example of Abstract class that has an abstract method
abstract class Bike
{
abstract void run();
}
class Honda extends Bike
{
void run()
{
System.out.println("running safely
");
}
public static void main(String ar
gs[])
{
Bike obj = new Honda();
obj.run();
}
}
Understanding the real scenario of Abstract class
abstract class Shape
{
abstract void draw();
}
class Rectangle extends Shape
{
void draw()
{
System.out.println("drawing rectang
le");
}
}
class Circle1 extends Shape
{
void draw()
{
System.out.println("drawing circle")
;
}
}
class TestAbstraction1
{
public static void
main(String args[])
{
Shape s=new Circl
e1();
s.draw();
}
}
Interface in Java
• An interface in Java is a blueprint of a class. It has
static constants and abstract methods.
• The interface in Java is a mechanism to
achieve abstraction. There can be only abstract
methods in the Java interface, not method body. It
is used to achieve abstraction and
multiple inheritance in Java.
• Java Interface also represents the IS-A relationship.
• It cannot be instantiated just like the abstract class.
How to declare an interface?
• An interface is declared by using the interface keyword.
• It provides total abstraction; means all the methods in an
interface are declared with the empty body, and all the fields
are public, static and final by default.
• A class that implements an interface must implement all the
methods declared in the interface.
Syntax:
interface <interface_name>{
// declare constant fields
// declare methods that abstract
// by default.
}
Internal addition by the compiler
Interface fields are public, static and final by default, and the methods
are public and abstract.
The relationship between classes and interfaces
• As shown in the figure given below, a class extends
another class, an interface extends another interface,
but a class implements an interface.
Example
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();
}
}
//Interface declaration: by first user
interface Drawable
{
void draw();
}
//Implementation: by second user
class Rectangle implements Drawab
le
{
public void draw()
{
System.out.println("drawing r
ectangle");
}
}
class Circle implements Drawable
{
public void draw()
{
System.out.println("drawing c
ircle");
}
}
//Using interface: by third user
class TestInterface1
{
public static void main(String a
rgs[])
{
Drawable d=new Circle()
;
d.draw();
}
}
Multiple inheritance in Java by interface
• If a class implements multiple interfaces, or an
interface extends multiple interfaces, it is known as
multiple inheritance.
Example
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();
}

More Related Content

What's hot (20)

PDF
Polymorphism In Java
Spotle.ai
 
PPTX
Type casting in java
Farooq Baloch
 
PPT
Method overriding
Azaz Maverick
 
PPTX
OOPS Basics With Example
Thooyavan Venkatachalam
 
PPTX
Java constructors
QUONTRASOLUTIONS
 
PPTX
Polymorphism in java
Elizabeth alexander
 
PPTX
Array of objects.pptx
RAGAVIC2
 
ODP
OOP java
xball977
 
PPTX
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
PDF
Arrays in Java
Naz Abdalla
 
PPTX
Java exception handling
BHUVIJAYAVELU
 
PPTX
Inheritance in JAVA PPT
Pooja Jaiswal
 
PPT
Class and object in C++
rprajat007
 
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
PPTX
Abstract class in c++
Sujan Mia
 
PPS
Wrapper class
kamal kotecha
 
PPTX
Oop c++class(final).ppt
Alok Kumar
 
PPTX
Threads in JAVA
Haldia Institute of Technology
 
PPTX
Inner classes in java
PhD Research Scholar
 
PPTX
constructors in java ppt
kunal kishore
 
Polymorphism In Java
Spotle.ai
 
Type casting in java
Farooq Baloch
 
Method overriding
Azaz Maverick
 
OOPS Basics With Example
Thooyavan Venkatachalam
 
Java constructors
QUONTRASOLUTIONS
 
Polymorphism in java
Elizabeth alexander
 
Array of objects.pptx
RAGAVIC2
 
OOP java
xball977
 
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
Arrays in Java
Naz Abdalla
 
Java exception handling
BHUVIJAYAVELU
 
Inheritance in JAVA PPT
Pooja Jaiswal
 
Class and object in C++
rprajat007
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Abstract class in c++
Sujan Mia
 
Wrapper class
kamal kotecha
 
Oop c++class(final).ppt
Alok Kumar
 
Inner classes in java
PhD Research Scholar
 
constructors in java ppt
kunal kishore
 

Similar to ABSTRACT CLASSES AND INTERFACES.ppt (20)

PPTX
abstract,final,interface (1).pptx upload
dashpayal697
 
PPTX
Lecture-on-Object-Oriented-Programming-Language-Java.pptx
officialpriyanshu228
 
PDF
Exception handling and packages.pdf
Kp Sharma
 
PDF
Abstraction in Java: Abstract class and Interfaces
Jamsher bhanbhro
 
PPTX
06_OOVP.pptx object oriented and visual programming
deffa5
 
PPTX
BCA Abstraction.pptx
sarthakgithub
 
PDF
Basic_Java_10.pdf
KumarUtsav24
 
DOCX
Core java notes with examples
bindur87
 
PPTX
Interface in java
Kavitha713564
 
PPTX
A class which is declared with the abstract keyword is known as an abstract c...
Kavitha S
 
PDF
java-06inheritance
Arjun Shanka
 
PDF
Advanced Programming _Abstract Classes vs Interfaces (Java)
Professor Lili Saghafi
 
PPTX
Lecture 18
talha ijaz
 
PPTX
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
PDF
Java 06
Loida Igama
 
PPTX
Abstract Class and Interface for Java Intoductory course.pptx
DrShamimAlMamun
 
PPT
Java interfaces & abstract classes
Shreyans Pathak
 
DOCX
Java interface
HoneyChintal
 
PPTX
More oop in java
SAGARDAVE29
 
PDF
Java abstract Keyword.pdf
SudhanshiBakre1
 
abstract,final,interface (1).pptx upload
dashpayal697
 
Lecture-on-Object-Oriented-Programming-Language-Java.pptx
officialpriyanshu228
 
Exception handling and packages.pdf
Kp Sharma
 
Abstraction in Java: Abstract class and Interfaces
Jamsher bhanbhro
 
06_OOVP.pptx object oriented and visual programming
deffa5
 
BCA Abstraction.pptx
sarthakgithub
 
Basic_Java_10.pdf
KumarUtsav24
 
Core java notes with examples
bindur87
 
Interface in java
Kavitha713564
 
A class which is declared with the abstract keyword is known as an abstract c...
Kavitha S
 
java-06inheritance
Arjun Shanka
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Professor Lili Saghafi
 
Lecture 18
talha ijaz
 
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
Java 06
Loida Igama
 
Abstract Class and Interface for Java Intoductory course.pptx
DrShamimAlMamun
 
Java interfaces & abstract classes
Shreyans Pathak
 
Java interface
HoneyChintal
 
More oop in java
SAGARDAVE29
 
Java abstract Keyword.pdf
SudhanshiBakre1
 
Ad

Recently uploaded (20)

PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Ad

ABSTRACT CLASSES AND INTERFACES.ppt

  • 2. Abstract class in Java • A class which is declared with the abstract keyword is known as an abstract class in Java. It can have abstract and non-abstract methods (method with the body). Abstraction in Java • Abstraction is a process of hiding the implementation details and showing only functionality to the user. • Another way, it shows only essential things to the user and hides the internal details. Abstraction lets you focus on what the object does instead of how it does it. • There are two ways to achieve abstraction in java ✔ Abstract class (0 to 100%) ✔ Interface (100%)
  • 3. Abstract class in Java • A class which is declared as abstract is known as an abstract class. It can have abstract and non-abstract methods. It needs to be extended and its method implemented. It cannot be instantiated. • Points to Remember • An abstract class must be declared with an abstract keyword. • It can have abstract and non-abstract methods. • It cannot be instantiated. • It can have constructors and static methods also. • It can have final methods which will force the subclass not to change the body of the method. Example of abstract class abstract class A{}
  • 4. Abstract Method in Java • A method which is declared as abstract and does not have implementation is known as an abstract method. Example of abstract method abstract void printStatus();//no method body and abst ract
  • 5. Example of Abstract class that has an abstract method abstract class Bike { abstract void run(); } class Honda extends Bike { void run() { System.out.println("running safely "); } public static void main(String ar gs[]) { Bike obj = new Honda(); obj.run(); } }
  • 6. Understanding the real scenario of Abstract class abstract class Shape { abstract void draw(); } class Rectangle extends Shape { void draw() { System.out.println("drawing rectang le"); } } class Circle1 extends Shape { void draw() { System.out.println("drawing circle") ; } } class TestAbstraction1 { public static void main(String args[]) { Shape s=new Circl e1(); s.draw(); } }
  • 7. Interface in Java • An interface in Java is a blueprint of a class. It has static constants and abstract methods. • The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance in Java. • Java Interface also represents the IS-A relationship. • It cannot be instantiated just like the abstract class.
  • 8. How to declare an interface? • An interface is declared by using the interface keyword. • It provides total abstraction; means all the methods in an interface are declared with the empty body, and all the fields are public, static and final by default. • A class that implements an interface must implement all the methods declared in the interface. Syntax: interface <interface_name>{ // declare constant fields // declare methods that abstract // by default. }
  • 9. Internal addition by the compiler Interface fields are public, static and final by default, and the methods are public and abstract.
  • 10. The relationship between classes and interfaces • As shown in the figure given below, a class extends another class, an interface extends another interface, but a class implements an interface.
  • 11. Example 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(); } }
  • 12. //Interface declaration: by first user interface Drawable { void draw(); } //Implementation: by second user class Rectangle implements Drawab le { public void draw() { System.out.println("drawing r ectangle"); } } class Circle implements Drawable { public void draw() { System.out.println("drawing c ircle"); } } //Using interface: by third user class TestInterface1 { public static void main(String a rgs[]) { Drawable d=new Circle() ; d.draw(); } }
  • 13. Multiple inheritance in Java by interface • If a class implements multiple interfaces, or an interface extends multiple interfaces, it is known as multiple inheritance.
  • 14. Example 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(); }