answersLogoWhite

0


Best Answer

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 SubClass

System.out.println("SubClass Method");

}

}

class Example{

public static void main(String... args){

SuperClass sup=new SubClass();

sup.show(); //SubClass show() will be executed !!!

}

}

User Avatar

Wiki User

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

Wiki User

12y ago

yes,abstract class can have non abstract methods,even it can have all non abstract method

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

yes

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you call an abstract method from a non abstract method in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can you refer non static method from static content in java?

Shortly, you can not.Different approaches are however available.1. Put your non static method in different class. Then call it from your static content by first instantiating the class.2. Make a duplicate static method for your non static method and use from your static content.


Can you non-recursively call a method you are currently in in Java?

The definition of recursion states that each method call after the initial one must be influenced by the previous call (its results must depend on the results to previous calls). While this can lead to a method calling itself in a non-recursive way, it seems that it is also a sign of poor coding style and hard to read methods.


What can be declared in an abstract class?

Abstract classes are to be extended until to a concrete class.Can have both abstract & non abstract methods.An Abstract class can not be instantiated.A non abstract class can be extended to an abstract class.If At least one abstract method present in a class then that class must be abstract.abstract & final modifiers can never be together.abstract classes can have both abstract methods & non abstract methods.


What are abstract classin java?

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.A Child Class extending the Abstract Class:public class Child extends Parent {public String getSon() {return "Sons Name";}public String getDaughter(){return "Daughters Name";}...... //Code specific to the Child class}


What is non-instantiable class?

A non-instantiable class is the class whose object can be created but cannot be initialized. for example the interfaces and the abstract classes in java.

Related questions

Can you refer static method from non static method in java?

Yes, it is possible to call a static method from a non-static method. However, it is not possible to call a non-static method from a static method without first having an instance to operate on.


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 you refer non static method from static content in java?

Shortly, you can not.Different approaches are however available.1. Put your non static method in different class. Then call it from your static content by first instantiating the class.2. Make a duplicate static method for your non static method and use from your static content.


Can you non-recursively call a method you are currently in in Java?

The definition of recursion states that each method call after the initial one must be influenced by the previous call (its results must depend on the results to previous calls). While this can lead to a method calling itself in a non-recursive way, it seems that it is also a sign of poor coding style and hard to read methods.


What can be declared in an abstract class?

Abstract classes are to be extended until to a concrete class.Can have both abstract & non abstract methods.An Abstract class can not be instantiated.A non abstract class can be extended to an abstract class.If At least one abstract method present in a class then that class must be abstract.abstract & final modifiers can never be together.abstract classes can have both abstract methods & non abstract methods.


What are abstract classin java?

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.A Child Class extending the Abstract Class:public class Child extends Parent {public String getSon() {return "Sons Name";}public String getDaughter(){return "Daughters Name";}...... //Code specific to the Child class}


What is non-instantiable class?

A non-instantiable class is the class whose object can be created but cannot be initialized. for example the interfaces and the abstract classes in java.


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

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.


What is classes instantiating?

A non-instantiable class is the class whose object can be created but cannot be initialized. for example the interfaces and the abstract classes in java.


How objets call from class in java?

if we are acessing static members we can call them directly,while coming to non static members inorder to call object we have to call by using new operator......


What is a good Java book for experienced non-Java programmer?

Java cook book


Can main method be non-static?

No, the reason is simple: A method marked as a static means, that you don't need create an instance (create an object with the 'new' operator) in order to use it. The main method is the entry point for a java application, therefor there is nothing after you call it. no one who can create an object of the type of your class and call the main method. So the jvm must call the main method with no object reference.