answersLogoWhite

0

What is Abstraction in C?

Updated: 8/10/2023
User Avatar

Wiki User

7y ago

Best Answer

C is not an object-oriented programming language and therefore has no concept of abstract classes.

In C++, however, an abstract class is a base class that declares one or more pure-virtual functions. An abstract base class is also known as an abstract data type (ADT). Pure-virtual functions differ from virtual functions in that virtual functions are expected to be overridden (but needn't be) while a pure-virtual function must be overridden (but needn't be implemented by the ADT). Once overridden by a derived class, the function reverts to being a virtual function with respect to further derivatives. However, only classes that provide or inherit a complete implementation of the pure-virtual interface can be instantiated in their own right; those that do not are themselves abstract data types.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

An abstract class is a class which has atleast one pure virtual function.An abstract class does not have any objects.It is used just for sharing it's members to some other classes.the class that shares the members of base class should define the pure virtual function if not object is not been created

for example:

class classname

{

protected:

virtual datatype fname(parameters)=0;

};

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

Abstraction in any programming language is a higher-level construct that implements some lower-level functionality. To a large extent, we use abstractions to simplify our code. For instance, the C standard library consists of a number of low-level functions which we can combine in some way to create a higher-level function, thus increasing the level of abstraction. We can then combine these higher-level functions to increase the level of abstraction even further. With well-named abstractions, our code becomes largely self-documenting and thus easier to both read and maintain.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

An Abstract class is a special kind of class that cannot be instantiated. It has one or more methods which are not implemented in the class. These methods are declared abstract and they do not contain any code inside them.

Ex:

abstract class Parent {

public abstract String getSon();

public abstract String getDaughter();

....

....

//More methods that contain specific behaviour/code in them

}

The above is an abstract class "Parent" that has a lot of functionality but it has declared two abstract methods which have no code inside them. Any class that has one or more abstract methods has to be abstract. This abstract class cannot be instantiated.

i.e., the below piece of code will not work. The code will not even compile.

Parent object = new Parent();

Purpose of Abstract Classes:

Abstract classes are generally used where you want an amount of behaviour to be used by the class that extends the abstract class while at the same time giving options to the child class to provide a certain amount of behaviour itself.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

An abstract class is an abstract data type (ADT). An ADT has one or more pure-virtual functions that must be implemented in derived classes or they, too, become abstract. ADTs cannot be instantiated, even if they provide implementations for their pure-virtual functions. They are intended to be derived -- they merely provide the definition of an interface for those derivatives.

A virtual class is used when a derived class uses multiple inheritance, where two or more of the base classes inherit from a common base class. Since the derived class would inherit two or more versions of the common base class, an ambiguity exists as to which common base class would be used via implicit calls in the derived class. One way around this is to use explicit calls from the derived class. But by declaring all but one of the base classes to be virtual, only one copy of the common base class will be visible to the derived class.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Abstract classes are the same as abstract data types. They are conceptual, incomplete types, that are intended to act as base classes for other classes (both abstract and concrete) that ultimately share the common interface provided by the abstract base class. Being abstract, they cannot be instantiated directly, they must be derived from.

In order to become abstract, a class must have at least one pure-virtual method. All derivatives of an abstract base class must provide an implementation for all the base class' pure-virtual methods, otherwise they become abstract themselves. However, any implementations they do provide then become virtual methods, which can subsequently be inherited by further derivation. Only classes that provide or inherit a complete implementation for all pure-virtual methods can be physically instantiated (a concrete class).

To use an example, circles and squares are concrete classes that can be derived from a generic shape class. Since all shapes can be drawn it makes sense to percolate the draw() method up to the base class. However, the shape class cannot implement the draw() method without knowing what type of shape is derived from it. Thus the draw() method must be declared pure-virtual which renders the entire shape class abstract. This means we can no longer instantiate a shape class, but that's not a problem because we're only interested in instantiating concrete shapes like circles and squares, and any other type of shape we might choose to derive from shape in the future. The pure-virtual draw() method ensures that all derivatives provide their own specific draw() methods, thus the shape class need not even be aware of what types of shape are derived from it. It's merely providing a common interface for all types of shape.

Although we cannot instantiate a shape class directly, we can point or refer to the underlying shape class of any derivative. Thus we can create a collection of different shapes and call their draw methods without any regard to what types of shape they actually are. Each shape draws itself according to the derived class implementation which is guaranteed to exist otherwise the derived class simply would not exist.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

a abstract class is class which has a abstract method which means a method does not its own body.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

To provide a generic interface for two or more concrete classes.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is Abstraction in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can abstraction encapsulation be achieved in C program if yes explain?

abstraction and encapsulation is one of the concepts of OOPs and C is not an OOP [Object Oriented Programming language] obviously abst & encap will not be supported by 'C' Abstraction & encapsulation is a concept of OOP [Object Oriented Programming] But, 'C' is not an OOP whereas it is a POP [Procedure oriented programming], so obviously 'C' does not support abstraction and encapsulation Answer Encapsulation is not inherently supported but it can be emulated in C. The use of static and extern keywords for functions are almost equivalent to your private and public keywords in java (encapsulation). Read up more on those keywords.. Structures become an object's attributes while functions accepting pointers the the said struct become its methods.


What c plus plus programming statements to implement data abstraction?

Data abstraction is a design concept, whereby interfaces and implementations are kept separate. That is, it should not be necessary to know how an object works in order to use it. The interface provides all you need to know. This reflects much of real life. When watching TV, you have a remote control which allows you to select a channel, but it is not necessary to know how the TV receives and processes radio signals, nor how it separates one channel from another. Those are implementation details that are only of concern to TV engineers. In C++, there are no statements as such to implement data abstraction. You achieve it by designing a public interface which is accessible to normal users, and a private interface that is only accessible to the class designer.


What is meant by abstraction in c plus plus?

Abstraction is a process by which higher concepts are derived from the usage and classification of literal ("real" or "concrete") concepts, first principles and/or other abstractions.


Which languages support multiple interface?

If by interface you mean, a mechanism to achieve abstraction and create a blueprint for future implementation. Java/C#/C++ all allow for multiple interfaces(abstract classes in C++) to be implemented.


Is it necessary to know C or C plus plus to learn matlab?

No. Both C and C++ are low- to mid-level languages while MATLAB is a high-level language. The level determines the amount of abstraction involved, and the higher the amount of abstraction, the easier a language is to use. Knowledge of another language is never a bad thing though. The more languages you are familiar with, the more easily you can determine which language is best suited to a particular solution.

Related questions

What is data abstraction in c sharp?

Abstraction means that all information exist but only the relevent information is provided to the user. Encapsulation assists abstraction by providing a mean of suppressing the non-essential details.


What has the author R C B Cooper written?

R. C. B. Cooper has written: 'Preserving abstraction in concurrent programming'


Can abstraction encapsulation be achieved in C program if yes explain?

abstraction and encapsulation is one of the concepts of OOPs and C is not an OOP [Object Oriented Programming language] obviously abst & encap will not be supported by 'C' Abstraction & encapsulation is a concept of OOP [Object Oriented Programming] But, 'C' is not an OOP whereas it is a POP [Procedure oriented programming], so obviously 'C' does not support abstraction and encapsulation Answer Encapsulation is not inherently supported but it can be emulated in C. The use of static and extern keywords for functions are almost equivalent to your private and public keywords in java (encapsulation). Read up more on those keywords.. Structures become an object's attributes while functions accepting pointers the the said struct become its methods.


In computer terms What is the diffference between C and C plus plus?

In computer terms there is no difference. The difference is only in the high-level abstraction which is only of relevance to programmers, and of no relevance to computers. The resulting machine code is the same for any given program, the only real difference being how the code is optimised. Ultimately, C and C++ are merely tools to produce machine code programs -- they just achieve it in different ways. That is, anything you can do with C++ you can also do with C, it just requires more effort because of the reduced abstraction in C. By the same token, anything you can do in C you can also do in assembly language, which has the lowest level of abstraction.


What c plus plus programming statements to implement data abstraction?

Data abstraction is a design concept, whereby interfaces and implementations are kept separate. That is, it should not be necessary to know how an object works in order to use it. The interface provides all you need to know. This reflects much of real life. When watching TV, you have a remote control which allows you to select a channel, but it is not necessary to know how the TV receives and processes radio signals, nor how it separates one channel from another. Those are implementation details that are only of concern to TV engineers. In C++, there are no statements as such to implement data abstraction. You achieve it by designing a public interface which is accessible to normal users, and a private interface that is only accessible to the class designer.


Why do we use C language?

We use C when we want to write low-level code with a higher level of abstraction than that provided by assembly language.


What is meant by abstraction in c plus plus?

Abstraction is a process by which higher concepts are derived from the usage and classification of literal ("real" or "concrete") concepts, first principles and/or other abstractions.


When was In Abstraction created?

In Abstraction was created on 2011-12-06.


What are the concepts of object oriented programming in c plus plus?

The concepts of OOP in C++ are the same as for OOP in any other programming language: abstraction, encapsulation, inheritance and polymorphism.


Which languages support multiple interface?

If by interface you mean, a mechanism to achieve abstraction and create a blueprint for future implementation. Java/C#/C++ all allow for multiple interfaces(abstract classes in C++) to be implemented.


Is it necessary to know C or C plus plus to learn matlab?

No. Both C and C++ are low- to mid-level languages while MATLAB is a high-level language. The level determines the amount of abstraction involved, and the higher the amount of abstraction, the easier a language is to use. Knowledge of another language is never a bad thing though. The more languages you are familiar with, the more easily you can determine which language is best suited to a particular solution.


What term refers to presenting an image so realistically that it has no hidden meaning A allusion B Literism C Personifiction D Abstraction?

the answer is allusion