type of abstraction programming example

A type of  abstraction programming example: Abstraction can be of two types, namely, data abstraction and control abstraction. In an object-oriented approach, one can abstract both data and functions. Data abstraction ensures the security of data by preventing it from accidental changes or manipulations by other parts of the program.

Type of  abstraction programming exampleof c++

 

In C++, header files are a different kind of abstraction. For instance, if we include the cmath or math.h header file at the beginning of the programme, we may use the sqrt() function to determine the square root of any given number.

 

 

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

double num, answer;

cout<<“Enter a number: “;

cin>>num;

answer = sqrt(num);

cout << “\n Square root of ” << num << ” is ” << answer ;

}

Type of  abstraction programming example in java

 

By virtue of the quality of abstraction in Java, the user only sees the most important information. For instance, a car is seen as a whole rather than as its distinct parts.

 

Java achieves abstraction through the use of interfaces and abstract classes. By using interfaces, we can achieve complete Abstraction computer science.

 

Type of  abstraction programming example  code in java

 

// Java program to illustrate the

// concept of Abstraction

abstract class Shape {

String color;

 

// these are abstract methods

abstract double area();

public abstract String toString();

 

// abstract class can have the constructor

public Shape(String color)

{

System.out.println(“Shape constructor called”);

this.color = color;

}

 

// this is a concrete method

public String getColor() { return color; }

}

class Circle extends Shape {

double radius;

 

public Circle(String color, double radius)

{

 

// calling Shape constructor

super(color);

System.out.println(“Circle constructor called”);

this.radius = radius;

}

 

@Override double area()

{

return Math.PI * Math.pow(radius, 2);

}

 

@Override public String toString()

{

return “Circle color is ” + super.getColor()

+ “and area is : ” + area();

}

}

class Rectangle extends Shape {

 

double length;

double width;

 

public Rectangle(String color, double length,

double width)

{

// calling Shape constructor

super(color);

System.out.println(“Rectangle constructor called”);

this.length = length;

this.width = width;

}

 

@Override double area() { return length * width; }

 

@Override public String toString()

{

return “Rectangle color is ” + super.getColor()

+ “and area is : ” + area();

}

}

public class Test {

public static void main(String[] args)

{

Shape s1 = new Circle(“Red”, 2.2);

Shape s2 = new Rectangle(“Yellow”, 2, 4);

 

System.out.println(s1.toString());

System.out.println(s2.toString());

}

}

 

Type of  abstraction programming example definition

 

For instance, when you wash your clothes in a washing machine, you insert the clothing and detergent before waiting for the machine to finish its work. How does the machine wash your clothes, though? What system does it employ?

 

The engineering behind its operation needs not be understood by the user. Similar to data abstraction, this approach conceals from users all information that is not necessary.

 

Type of  abstraction programming example data structure

 

A data structure is a method of categorising data to enable effective use of the data. The data structure can be seen in two different ways:

 

  • Mathematics, logic, abstract models, and points of view: a data structure is a system for arranging data that entails

 

  • protocols or rules. The rules that fall within the logical/abstract model need to be modelled.

 

  • Implementation: The second component consists of this. Programming language implementation is required for the regulations.

 

Type of  abstraction programming example javascript

 

An Abstract Data Type is a technique for keeping implementation specifics hidden from consumers and simply displaying functionality. In other words, it ignores the extraneous information and just displays what is necessary.

Type of  abstraction programming example

 

<script>  

//Creating a constructor function  

function Vehicle()  

{  

   this.vehicleName= vehicleName;  

    throw new Error(“You cannot create an instance of Abstract class”);  

  

}  

Vehicle.prototype.display=function()  

{  

    return this.vehicleName;  

}  

var vehicle=new Vehicle();  

   </script>  

 

Type of  abstraction programming example in python

 

Utilizing abstraction in programming classes and interfaces in Python is one way to create abstraction. Abstraction is used to shield users from the inner workings of a function. Users only engage with the function’s most basic version; they are unaware of how it operates behind the scenes.

 

Type of  abstraction programming example :

 

# Python program demonstrate

# abstract base class work

from abc import ABC, abstractmethod

class Car(ABC):

def mileage(self):

pass

 

class Tesla(Car):

def mileage(self):

print(“The mileage is 30kmph”)

class Suzuki(Car):

def mileage(self):

print(“The mileage is 25kmph “)

class Duster(Car):

def mileage(self):

print(“The mileage is 24kmph “)

 

class Renault(Car):

def mileage(self):

print(“The mileage is 27kmph “)

 

# Driver code

t= Tesla ()

t.mileage()

 

r = Renault()

r.mileage()

 

s = Suzuki()

s.mileage()

d = Duster()

d.mileage()

 

Types of abstraction in art

 

We can categorise abstract art into six fundamental categories to keep things simple:

 

  • Curvilinear
  • colour or light related
  • geometric emotional or intuitive
  • gestural
  • minimal

 

Types of abstraction in python

 

Using ABC (abstraction class) or abstract methods, we can implement abstraction in Python. ABC is a class in Python’s abc module. Classes that inherit from this class will be required to implement any abstraction methods we add if we extend any other classes with ABC.

 

Types of abstraction in java

 

One of the fundamental ideas in both nature and object-oriented programming (OOP) is abstraction. Consider how something is created in the natural or physical world. Atoms and molecules are the only components of matter at the most fundamental levels.

What are the types of abstraction?

 

To enable one to concentrate on the most important aspects at once, syntactic type abstraction is a technique for hiding unimportant elements and representing only the key features.

 

Both data and functions can be abstracted when using an object-oriented approach. There are two different types of abstraction: data abstraction and control abstraction.

5 type of  abstraction programming example

 

Example 1

abstract class Base {

abstract void fun();

}

 

// Class 2

class Derived extends Base {

void fun()

{

System.out.println(“Derived fun() called”);

}

}

 

// Class 3

// Main class

class Main {

 

// Main driver method

public static void main(String args[])

{

 

// Uncommenting the following line will cause

// compiler error as the line tries to create an

// instance of abstract class. Base b = new Base();

 

// We can have references of Base type.

Base b = new Derived();

b.fun();

}

}

Output

Derived fun() called

 

Example 2

abstract class Base {

 

// Constructor of class 1

Base()

{

// Print statement

System.out.println(“Base Constructor Called”);

}

 

// Abstract method inside class1

abstract void fun();

}

 

// Class 2

class Derived extends Base {

 

// Constructor of class2

Derived()

{

System.out.println(“Derived Constructor Called”);

}

 

// Method of class2

void fun()

{

System.out.println(“Derived fun() called”);

}

}

 

// Class 3

// Main class

class GFG {

 

// Main driver method

public static void main(String args[])

{

// Creating object of class 2

// inside main() method

Derived d = new Derived();

d.fun();

}

}

Output

Base Constructor Called

Derived Constructor Called

Derived fun() called

 

Example 3

abstract class Base {

 

// Demo method. This is not an abstract method.

void fun()

{

// Print message if class 1 function is called

System.out.println(“Function of Base class is called”);

}

}

 

// Class 2

class Derived extends Base {

//This class only inherits the Base class methods and properties

 

}

 

// Class 3

class Main {

 

// Main driver method

public static void main(String args[])

{

// Creating object of class 2

Derived d = new Derived();

 

// Calling function defined in class 1 inside main()

// with object of class 2 inside main() method

d.fun();

}

}

Output

Function of Base class is called

Example 4

abstract class Base {

 

final void fun()

{

System.out.println(“Base fun() called”);

}

}

 

// Class 2

class Derived extends Base {

 

}

 

// Class 3

// Main class

class GFG {

 

// Main driver method

public static void main(String args[])

{

 

// Creating object of abstract class

Base b = new Derived();

 

// Calling method on object created above

// inside main()

b.fun();

}

}

Output

Base fun() called

Example 5

abstract class Helper {

 

// Abstract method

static void demofun()

{

 

// Print statement

System.out.println(“Geeks for Geeks”);

}

}

 

// Class 2

// Main class extending Helper class

public class GFG extends Helper {

 

// Main driver method

public static void main(String[] args)

{

 

// Calling method inside main()

// as defined in above class

Helper.demofun();

}

}

Output

Geeks for Geeks

 

Conclusion

 

I sincerely hope you had fun reading it and learned a little bit about Python. This should answer any queries you may have regarding identifiers in Python and get you started on your programming journey.

 

In terms of potential, this is merely the tip of the iceberg. Generators, decorators, OOP, and other concepts are far more challenging to comprehend. It is necessary to first study the type of  abstraction programming example.

Read more blog: python training in Delhi

 

Leave a Comment

Your email address will not be published. Required fields are marked *