answersLogoWhite

0

Why you are not allowed to put an abstract method into a normal class?

Updated: 8/20/2019
User Avatar

Vankwisha

Lvl 1
12y ago

Best Answer

You can't put an abstract method (pure-virtual method) in a normal class because the normal class would become abstract itself. Only non-abstract classes can be physically instantiated as objects, and only if they fully implement all the abstract methods inherited from their base classes.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why you are not allowed to put an abstract method into a normal class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between abstract class and normal class?

Any class which has one or more abstract methods is called an abstract class. But in the normal class we can't have any abstract methods. We cannot create an object for the abstract classes. When we inherit the abstract class we should implement the abstract method which we inherit.


When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


How do you create a concrete method inside abstract class?

The same way you create a concrete method in a concrete class. When a class is abstract, it can contain abstract methods. That doesn't mean that all methods must be abstract. Hope this helps.


What is an interface class and what is an abstract class?

The term interface class does not exist in C#. If this is a term describing a class being an interface to other component (human, subsystems, etc), it is very application specific. The designer of that application should know the abstraction.However, C# does have another type called interface. An interface is NOT a class. An interface defines the intention of some behaviors that classes may be extended it and provides the implementation. The intention, is nothing but method signatures, which defines the return data type, the method name, and any method arguments and associated data type. The implementation is the code of the method. Interface is used for separating the concern of design and implementation.Abstract class is a class with abstract keyword. It can be just like a class without that keyword (then, why it is an abstract class?). But it may have some methods or properties defined as abstract. These abstract methods, like the method signatures of an interface, defines the intention.The subclasses of such an abstract class would need to implement those abstract methods (providing the code).There are more common, differences between interfaces and abstract classes, please see answer(s) of those related questions in C# category.


How do you write concrete method inside abstract class?

There is no difference with method declaration and implementation between abstract and non-abstract classes. You do the exact same thing when writing a concrete method in either an abstract or non-abstract class.


Can abstract method be overriden?

An overridden method is one which has already been implemented in the parent class with the same signature but has again been coded in the current class for functionality requirements. An abstract method is one which has only been declared in a class and would have to be implemented by the class that extends this abstract class. The implementation for the method is not available in the class in which it is declared.


Can abstract class have constructors?

A constructor of a class in invoked when a object of that class is created. As an abstract class can't have an object, so we can't create a constructor of the abstract class. But we can create a constructor of a concrete subclass of that abstract class and we have to pass the object of that concrete subclass to the abstract class.


Can you call an abstract method from a non abstract method in java?

We can't call (i.e, execute) an abstract method in java because these methods don't contain any code to execute!In some special cases like when an abstract method is overridden in a subclass, and when we are using super class reference variable( which is referring that subclass object), it appears that we are calling abstract method in super class. But actually the code in the subclass method is being executed.Example:abstract class SuperClass{abstract void show(); //abstract method in super class}class SubClass extends SuperClass{void show(){ //show() of SuperClass overridden in SubClassSystem.out.println("SubClass Method");}}class Example{public static void main(String... args){SuperClass sup=new SubClass();sup.show(); //SubClass show() will be executed !!!}}


What do mean by interface in java?

An interface in Java is like an abstract class, but there are no method bodies allowed in it and it has to be declared with the interface keyword. It is Java's way of getting around the Deadly Diamond of Death. Only abstract methods and constants are allowed in it.


How do you call an abstract class from main method?

An abstract class cannot have a constructor and hence you cannot invoke the constructor of the class - i.e., you can instantiate an abstract class and hence you cannot call the constructor of an abstract class.


What is abrstac class and virctul function in c?

I have to assume the question is for C#, not C, because C does not provide abstract class concept.public abstract class A1 { public virtual void SayHi() { Console.WriteLine("Hello World"); }public abstract void DoSomething();}The above abstract class A1 contains 1 virtual method and 1 abstract method. [Note that because of the abstract keyword for Dosomething(), A1 must be declared as abstract. An abstract class DOES NOT have to have any abstract methods!!)The virtual function SayHi() provides a implementation, while the abstract function provides nothing but only the method signature( the name of the method, the return type, and method parameters and their data types). The derived class of A1 has the option to override SayHi() and must implement (or defer to subclasses of this derived class) the method DoSomething()


Write a Java Program to illustarte the use of abstract methods?

Abstract MethodsAn abstract method is a method that's been declared as abstract but not implemented. In other words, the method contains no code. You mark a method abstract when you want to force subclasses to provide the implementation. (remember the reason why you would want to make a class abstract from the previous paragraph)Ex: public abstract void showSample();Notice that the abstract method ends with a semicolon instead of curly braces. It is illegal to have even a single abstract method in a class that is not explicitly declared abstract! Look at the following illegal class:public class IllegalAbstractClass{public abstract void test();}The preceding class will produce the following error if you try to compile it:IllegalClass.java:1: class IllegalAbstractClass must be declaredabstract.It does not define void test() from class IllegalAbstractClass.public class IllegalAbstractClass {1 errorYou can, however, have an abstract class with no abstract methods. The following example will compile fine:public abstract class LegalAbstractClass{void test() {// you can write lots of code here}}In the preceding example, test() is not abstract. Three different clues tell you it's not an abstract method:• The method is not marked abstract.• The method declaration includes curly braces, as opposed to ending in a semicolon. In other words, the method has a method body.• The method contains actual implementation code.Any class that extends an abstract class must implement all abstract methods of the superclass, unless the subclass is also abstract. The rule is this:The first concrete subclass of an abstract class must implement all abstract methods of the superclass.Concrete just means nonabstract, so if you have an abstract class extending another abstract class, the abstract subclass doesn't need to provide implementations for the inherited abstract methods. Sooner or later, though, somebody's going to make a nonabstract subclass (in other words, a class that can be instantiated), and that subclass will have to implement all the abstract methods from up the inheritance tree.