answersLogoWhite

0

An Abstract class is a way to organize inheritance, sometimes it makes no since to implement every method in a class (i.e. a predator class), it may implement some to pass to its children but some methods cannot be implemented without knowing what the class will do (i.e. eat() in a Tiger class). Therefore, abstract classes are templates for future specific classes.

A disadvantage is that abstract classes cannot be instantiated, but most of the time it is logical not to create a object of an abstract class. heloooooo

User Avatar

Wiki User

16y ago

What else can I help you with?

Continue Learning about Engineering

Is it necessary to provide a definition to the pure virtual function in the inherited derived class?

No, it is not necessary, but the derived class will be rendered abstract as well. Sometimes that can be desirable. Only derived classes that provide a complete implementation of all inherited pure-virtual methods can actually be instantiated. However, derived classes can also inherit pure-virtual implementations from any intermediate base classes, but not from the least-derived abstract base classes (where the pure-virtual methods originated). Abstract base classes can also provide their own default implementations of their own pure-virtual methods, but they cannot be called implicitly, even from the base class itself. These methods must still be overridden by derived classes, even if an override only needs to explicitly call the base class method.


What is abstract base class?

An abstract class is a class that cannot be directly instantiated. The purpose of such a class is to put some logic in a base class and force derived classes to implement the remaining functionality. Since the full functionality is only available in the derived class, the base class is declared as abstract so that it cannot be instantiated directly.


What is the of abatract keyword in java 1.7?

"abstract" is used for a class that is not supposed to be instantiated directly. The reason this is used is because the class is not complete; the details are supposed to be filled out in subclasses (derived classes). An abstract class will usually have one or more abstract methods; a method that is declared by name (to make sure derived classes have this method), but without a method body.


When do you give preference to abstract classs and interface?

Abstract class provides a way of "being a [something like me]", or inheritance interface provides a set of functionality (contract) as "behaving". Abstract class provides the single inheritance and perhaps some default implementation, while interface may be implemented by different classes that have nothing to do one and other except the common interface implementation. The preference I would start with: Ask yourself that an object should be "Is a something or behave like something". If your answer is "Is a", then abstract class is more likely your good choice. But if your answer is behave like, does not need to Is a, then the interface is the way to go.


Is an abstract class cannot have any member variable in C plus plus?

An abstract base class may have member variables. Whether or not it actually needs member variables depends on the nature of the base class itself. If the variable is common to all derived classes, then it makes sense to place the variable in the base class. If some derived classes have no need of the variable, then it is better to derive an intermediate class with the variable, and to derive those classes that require that variable from the intermediate class, rather than directly from the abstract class.

Related Questions

What are the merits and demerits of defining and declaring a pure virtual function in a program?

Merits of defining a pure virtual function: It enforces derived classes to implement the function, ensuring polymorphic behavior. It enables abstract classes to define a common interface. Demerits: It can hinder flexibility as derived classes must implement the function. It may also increase code complexity.


Is it necessary to provide a definition to the pure virtual function in the inherited derived class?

No, it is not necessary, but the derived class will be rendered abstract as well. Sometimes that can be desirable. Only derived classes that provide a complete implementation of all inherited pure-virtual methods can actually be instantiated. However, derived classes can also inherit pure-virtual implementations from any intermediate base classes, but not from the least-derived abstract base classes (where the pure-virtual methods originated). Abstract base classes can also provide their own default implementations of their own pure-virtual methods, but they cannot be called implicitly, even from the base class itself. These methods must still be overridden by derived classes, even if an override only needs to explicitly call the base class method.


What is abstract base class?

An abstract class is a class that cannot be directly instantiated. The purpose of such a class is to put some logic in a base class and force derived classes to implement the remaining functionality. Since the full functionality is only available in the derived class, the base class is declared as abstract so that it cannot be instantiated directly.


What is the of abatract keyword in java 1.7?

"abstract" is used for a class that is not supposed to be instantiated directly. The reason this is used is because the class is not complete; the details are supposed to be filled out in subclasses (derived classes). An abstract class will usually have one or more abstract methods; a method that is declared by name (to make sure derived classes have this method), but without a method body.


When do you give preference to abstract classs and interface?

Abstract class provides a way of "being a [something like me]", or inheritance interface provides a set of functionality (contract) as "behaving". Abstract class provides the single inheritance and perhaps some default implementation, while interface may be implemented by different classes that have nothing to do one and other except the common interface implementation. The preference I would start with: Ask yourself that an object should be "Is a something or behave like something". If your answer is "Is a", then abstract class is more likely your good choice. But if your answer is behave like, does not need to Is a, then the interface is the way to go.


Is an abstract class cannot have any member variable in C plus plus?

An abstract base class may have member variables. Whether or not it actually needs member variables depends on the nature of the base class itself. If the variable is common to all derived classes, then it makes sense to place the variable in the base class. If some derived classes have no need of the variable, then it is better to derive an intermediate class with the variable, and to derive those classes that require that variable from the intermediate class, rather than directly from the abstract class.


What is the abstract feature in c plus plus?

Abstraction generally refers to abstract classes. An abstract class is one that cannot itself be instantiated, but can be derived from. Abstract classes are conceptual classes rather than concrete classes, and are intended to provide a common interface to the concrete classes derived from them. A class becomes abstract when it contains one or more pure-virtual methods, which must be implemented in the derived classes otherwise they become abstract classes themselves. A concrete class is one that provides a complete implementation for is abstract base classes, or inherits implementations from base classes other than those that originally declared the function to be pure-virtual. An example of an abstract class is Shape. All shapes can be drawn, therefore Shape will have a Draw() method. However, it cannot implement this method unless it knows what type of shape it actually is. Therefore the Draw() method should be declared pure-virtual, thus rendering the Shape class to be abstract. You can then derive concrete shapes from the Shape class, such as Circle and Square classes, which will each provide the actual implementation for the Draw() method. Since Square and Circle are types of Shape, you can create collections of Shape objects and call their Draw() methods without regard to their actual type. If the object is really a Square, then calling Shape.Draw() will actually invoke Square.Draw(). There is no need to determine the actual type of the shape because every shape has a common interface. This is really no different to overriding virtual methods in non-abstract classes. The main difference is that one would not be expected to instantiate a Shape (because it is abstract), other than through derivation, and the pure-virtual methods MUST be implemented by the derived classes, whereas normal virtual methods are simply expected to be overridden but it is not a requirement to do so unless you require an enhancement to the base class method. Abstract classes typically have few if any member variables and little or no implementation. Ultimately, the class exists purely to provide a common interface to all its derivatives, and only functionality and member variables that are common to all its derivatives should be placed within it. Even if the abstract class provides a complete implementation for all its pure-virtual methods, you cannot instantiate an abstract class -- it must be derived from -- and all pure-virtual methods must still be implemented in the derivatives, even if only to call the base class methods explicitly.


What is meant by function overriding in c plus plus?

Function overriding applies to class member functions (methods), where a derived class provides a more specialised implementation of its generic base class method. An override can still call the base class method and augment it with other instructions (before or after the call to the base class method), or it can provide a complete implementation of its own without calling the base class method. Classes that are intended to act as generic base classes will generally declare their methods to be virtual, meaning they are intended to be overridden, if required. Abstract base classes will contain one or more pure-virtual methods (which may or may not provide a generic implementation), meaning classes must be derived from the abstract base class and all the pure-virtual methods must be overridden in the derived class (otherwise they, too, become abstract). Only classes that fully implement all the pure-virtual methods they inherit from their base classes can actually be instantiated. That is, you cannot instantiate an instance of an abstract base class, even if it provides generic implementations for all its pure-virtual methods. They can only be instantiated by deriving classes from them.


How can you use abstract classes instead of interfaces?

In most cases, you will want to use abstract classes IN ADDITION to interfaces.You should use an abstract class in the following circumstance:the abstract class is clearly part of class hierarchy, and does not just describe some sort of basic functionality. Specifically, abstract classes are a good idea where they will be directly inherited from to create a concrete concept, but the abstract class itself is too indistinct to have any specific instance of it created.You want to provide an implementation for a set of methods that will be reused by a significant number of other classes, all of which can be fit into a class hierarchy.In practice, abstract classes are a good way to collect common code into one place, to make maintenance easier.For instance, say you have a class and interface structure like this:Class AInterface XClass B extends A implements XClass C extends A implements XBoth B and C will have the all the methods declared in X; if the implementation of those methods is the same (or can be made the same), then X is a good candidate for changing to an abstract method:Class AAbstract Class X extends AClass B extends XClass C extends XThus, you have removed the code duplication that was happening when using interfaces.Note that doing the above is NOT a good idea if any class which implement interface X cannot be made a subclass of the new abstract class X.


What are the differences between an abstract class and an interface in java?

They are very different. An abstract class is a class that represents an abstract concept (google define "abstract" if you're unsure) such as 'Thoughts' or 'BankAccount'. When a class is defined as abstract it cannot be used (directly) to create an object. Abstract classes are used as super-classes so that all of their subclasses inherit all methods. Interfaces can be thought of as contracts with all of their implementing classes. They simply require all implementing classes to have methods with the same signature as that defined in the interface, but such methods can behave as appropriate. Hope that helps :)


What is the difference between association class and abstract class in software designing?

Association class is describing the relationship between classes. An abstract class is just 1 class, provides some abstraction behaviors that may be (but do not have to) derived, overridden from.


What is a super class in terms of object oriented programming?

A superclass, also referred to as a parent class, is a class what which other classes are derived from. These derived classes are known as either subclasses or child classes.