---
title: "abstract class in oops"  
description: "in this article discus about abstraction in programming language ."  
author: "Ravi Vishwakarma"  
published: 2021-07-01  
updated: 2021-07-01  
canonical: https://www.mindstick.com/articles/327165/abstract-class-in-oops  
category: "java"  
tags: ["c#", "java", "c++"]  
reading_time: 3 minutes  

---

# abstract class in oops

## [Abstraction](https://www.mindstick.com/blog/668/abstraction-and-encapsulation)

Abstraction is a process of hiding the [implementation](https://yourviews.mindstick.com/view/60537/nationalwide-nrc-implementation-bjp-looting-congress-s-idea) details and showing the user [related data](https://www.mindstick.com/interview/22990/what-is-lazy-eager-and-explicit-loading-of-related-data-in-entity-frameworks). In other word hiding the critical data to use and showing only user related data, for example we are sending an email then type massage and send it doesn’t see how it is work. We do not know internal processing. This technique achieve by [abstract class](https://www.mindstick.com/blog/665/constructor-in-abstract-class-in-c-sharp). If we want to make a class is abstract then using abstract keyword before class declaration. In this class have two type of methods

## • [Abstract method](https://www.mindstick.com/articles/23305/abstract-methods-and-class-in-c-sharp)

## • Non-abstract method

• An abstract class must declare with abstract keyword

• It can have abstract and non-abstract method

• Doesn’t create object of this class

• This class can extended

• Every abstract method must override is [derived class](https://answers.mindstick.com/qa/30686/what-is-a-base-class-and-derived-class)

• It have [final method](https://www.mindstick.com/interview/2384/what-is-final-method-in-java)

## Syntax of declaring an abstract class

**abstract** class class-name{

member-variable 1 -----

member-variable 2 -----

member-variable n -----

return-type fuction_name()

{

}

// abstract method

abstract return-type function_name(); //

}

Example of abstract class

abstract class Person{

//variables of person class

private String personName;

private String personeAddress;

private int personeAge;

\

// creating constructor

Person(){

// [default constructor](https://www.mindstick.com/forum/34531/default-constructor)

}

Person(String personName,String personeAddress,int personeAge)

{

// parameterized constructor

this.personName=personName;

this.personeAddress=personeAddress;

this.personeAge=personeAge;

}

// methods of person class

[public void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) setPersoneName(String personName)

{

this.personName=personName;

}

public String getPersonName()

{

return this.personName;

}

public void setPersoneAddress(String personeAddress)

{

this.personeAddress=personeAddress;

}

public String getPersonAddress()

{

return this.personeAddress;

}

public void setPersoneAge(int personeAge)

{

this.personeAge=personeAge;

}

public int getPersonAge()

{

return this.personeAge;

}

@Override

public String toString()

{

return this.personName+' is belongs to '+personeAddress+' and age is '+personeAge+' year';

}

// declare the [abstract methods](https://www.mindstick.com/forum/159550/how-to-implement-an-interface-with-two-abstract-methods-by-a-lambda-expression) for datahiding

abstract public String getGoingTime();

abstract public String getReadingTime();

}

\

//declare a student class an dextende the persone class

class Student extends Person{

private String goingTime;

private String readingTime;

// parameterized constructor

Student(String studentName,String studentAddress, int age){

super(studentName,studentAddress,age);

}

Student(String studentName,String studentAddress, int age, String goingTime,String readingTime){

super(studentName,studentAddress,age);

this.goingTime=goingTime;

this.readingTime=readingTime;

}

@Override

public String getGoingTime()

{

if(goingTime==null)

return 'This student does't study.';

return 'This student going daily for study at '+goingTime+' AM';

}

@Override

public String getReadingTime()

{

if(readingTime==null)

return 'This student does't reading books ';

return 'This student daily reading for '+readingTime+' Hours';

}

}

//declare a NormalMan class an dextende the persone class

class NormalMan extends Person{

private String goingTime;

private String readingTime;

// parameterized constructor

NormalMan(String studentName,String studentAddress, int age){

super(studentName,studentAddress,age);

}

NormalMan(String studentName,String studentAddress, int age, String goingTime,String readingTime){

super(studentName,studentAddress,age);

this.goingTime=goingTime;

this.readingTime=readingTime;

}

@Override

public String getGoingTime()

{

if(goingTime==null)

return 'This person does't go office.';

return 'This person daily go office at '+goingTime+' AM';

}

@Override

public String getReadingTime()

{

if(readingTime==null)

return 'This perone is not reading a books. ';

return 'This person reading books for '+readingTime+' Hours ';

}

}

\

public class Main

{

public static void main (String[]args)

{

Person student=new Student('Ravi vishwakarma','Babhaniyav',22);

System.out.println(student);

System.out.println(student.getReadingTime());

System.out.println(student.getGoingTime()+'\n');

Person student1=new Student('Ravi sankar','Agra',18,'8:00','4');

System.out.println(student1);

System.out.println(student1.getReadingTime());

System.out.println(student1.getGoingTime()+'\n');

Person man=new NormalMan('Ravi vishwakarma','Babhaniyav',22);

System.out.println(man);

System.out.println(man.getReadingTime());

System.out.println(man.getGoingTime()+'\n');

Person man1=new NormalMan('Ravi sankar','Agra',18,'8:00','4');

System.out.println(man1);

System.out.println(man1.getReadingTime());

System.out.println(man1.getGoingTime()+'\n');

}

}

\

---

Original Source: https://www.mindstick.com/articles/327165/abstract-class-in-oops

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
