0% found this document useful (0 votes)
2 views5 pages

12 Java Abstraction PDF

The document explains the concept of abstraction in Object-Oriented Programming (OOP), highlighting its purpose to hide implementation details and only show essential features of an object. It details the requirements for creating abstract classes and methods, including the necessity to override abstract methods in child classes. Additionally, it provides sample Java code demonstrating the use of abstract classes and methods, along with non-abstract methods.

Uploaded by

Vignesh gs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

12 Java Abstraction PDF

The document explains the concept of abstraction in Object-Oriented Programming (OOP), highlighting its purpose to hide implementation details and only show essential features of an object. It details the requirements for creating abstract classes and methods, including the necessity to override abstract methods in child classes. Additionally, it provides sample Java code demonstrating the use of abstract classes and methods, along with non-abstract methods.

Uploaded by

Vignesh gs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

 Abstraction is one of the Object-Oriented

Programming concepts oops


 it’s used to hide the implementation details
and shows only the essential features of an
object.
 We can't Create an object for Abstract class
and to access abstract method we need to create
child class for abstract class and override
abstract method to child class
 Abstract method doesn't have an body to define
statements
 In Abstract extends with only one class but we
can create one or more child classes for
abstract class
 We can use any access modifiers and
constructors
 If we didn’t override a abstract method in
child class its throws an error to change child
class to abstract class
 If using abstract class compulsory we should be
use an abstract method and override to child
class
 If using abstract method in java class that
class should be changed to java abstract class

Sample program for abstract class:

package javaprogram;
// to abstract class need to use abstract keyword
//abstract class
abstract class connecting
{
// abstract methods doesn't have an body to
define statements
abstract void whatsapp();
abstract void instagram();
}
// subclass of abstract class
class Aravind extends connecting
{

void whatsapp()
{
System.out.println("Aravind we invite you for
special event.....");
}
void instagram()
{
System.out.print("I sended invite in whatsapp
doesn't seen ");
System.out.print("Aravind we invite you for
special event .....");
}
}
// subclass of abstract class
class Subhash extends connecting
{

void whatsapp()
{
System.out.println("Subhash we invite you for
special event.....");
}
void instagram()
{
System.out.print("I sended invite in whatsapp
doesn't seen ");
System.out.print("Subhash we invite you for
special event .....");
}
}
class Prakash extends connecting
{
void whatsapp()
{
System.out.println("Prakash we invite for
special event.....");
}
void instagram()
{
System.out.print("I sended invite in whatsapp
doesn't seen ");
System.out.print("Prakash we invite you for
special event .....");
}
}
public class TopicAbstraction{

public static void main(String[] args) {


// using runtime polymorphism(method
overriding in abstraction)
// connecting is a parent to override a
abstract method in Aravind subclass
connecting contactAravind=new Aravind();
contactAravind.whatsapp();
contactAravind.instagram();
// connecting is a parent to override a
abstract method in Subhash subclass
connecting contactSubhash=new Subhash();
contactSubhash.whatsapp();
contactSubhash.instagram();
// connecting is a parent to override a
abstract method in Prakash subclass
connecting contactprakash=new Prakash();
contactprakash.whatsapp();
contactprakash.instagram();
}
}
 We can use non-abstract method in java abstract
class it can have an body to define statements

package javaprogram;
// to abstract class need to use abstract keyword
//abstract class
abstract class connecting
{
// abstract methods doesn't have an body to
define statements
abstract void whatsapp();
// non-abstract method have an body
void messagesended()
{
System.out.println("message sended.....");
}
}
// subclass of abstract class
class Aravind extends connecting
{
void whatsapp()
{
System.out.println("Aravind we invite you for
special event.....");
}
}
// subclass of abstract class
class Subhash extends connecting
{
void whatsapp()
{
System.out.println("Subhash we invite you for
special event.....");
}
}
class Prakash extends connecting
{
void whatsapp()
{
System.out.println("Prakash we invite for
special event.....");
}
}
public class TopicAbstraction{

public static void main(String[] args) {


// using runtime polymorphism(method
overriding in abstraction)
// connecting is a parent to override a
abstract method in Aravind subclass
connecting contactAravind=new Aravind();
contactAravind.whatsapp();
contactAravind.messagesended();
// connecting is a parent to override a
abstract method in Subhash subclass
connecting contactSubhash=new Subhash();
contactSubhash.whatsapp();

// connecting is a parent to override a


abstract method in Prakash subclass
connecting contactprakash=new Prakash();
contactprakash.whatsapp();
contactprakash.messagesended();
}
}

You might also like