answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

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

Wiki User

10y ago

An abstract class(or classes) can't have a constructor and hence you cannot invoke the constructor of the class (for example, you can instantiate an abstract class and hence you cannot call the constructor of an abstract class).

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

You cannot. Abstract classes cannot be instantiated and hence cannot be invoked from the main method or any other class directly.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you call an abstract class from main method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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 !!!}}


When do you declare method or class final?

final is a keyword.it can be used for three posibilities. they are ->we can assign the variable as final. to declaring the variable as final to avoid the reusability of a variable. now i display small program for this type. class A { final int i=10; a(int b) { i=b; System.out.println(i); } } public static void main(String args[]) { A x=new A(20); } } to execute this program .we have an error message.i.e.,the variable i can not be override. ->to use method have final keyword it can not be override.and also ->to use classes has final they can not be inhereted to sub classes.


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.


What is a driver class in Java?

The driver class is often the class that contains the "Main" method.


Why main method is static?

Main method in java is always static as main method id the only method from where the program execution starts,and as we all know that main method is defined inside a class so JVM needs to make a object of the class to call the method and objects are build inside the main method ,so to execute the main method it has to make objects of the class but objects are build inside main method so that's the reason that main method is static so that JVM can execute the main method without making its object as static members can be called by class anme only

Related questions

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 !!!}}


How do you call main class with in main class in java?

We can't call a class. We always call a method in java.


How do you call a method from inside the main method?

I assume the question is about Java. How you call a method from inside the main method depends on whether this is an instance method or a static method. To call an instance method, you need to have a valid instance. Say foo is an instance of class Foo, which was created inside the main method. Then to call the instance method implode() use foo.implode() To call the static method bar() of class Foo, use Foo.bar().


Is it possible to override the main method in Java?

Theoretically yes. You will use only one main method for your whole java application and hence such a situation will not come up in real life. Imagine: You have a main in class A and one more in class B which extends class A. When you try to run the class B, only that main method will be executed and not the main in class A. So this override is irrelevant and we cannot call class A's main method at all


When do you declare method or class final?

final is a keyword.it can be used for three posibilities. they are ->we can assign the variable as final. to declaring the variable as final to avoid the reusability of a variable. now i display small program for this type. class A { final int i=10; a(int b) { i=b; System.out.println(i); } } public static void main(String args[]) { A x=new A(20); } } to execute this program .we have an error message.i.e.,the variable i can not be override. ->to use method have final keyword it can not be override.and also ->to use classes has final they can not be inhereted to sub classes.


Why main is static?

The main method is static because the JVM would be invoking this method as the starting point of execution. If this is like other normal methods, the JVM would have to instantiate an object of the class before it can call it. This is not possible because this is the starting point. If the main method is static the JVM can directly call this by specifying the class name.


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.


Are you allowed to declared main method in every class?

Yes. Every Java class can have a main method


Can you have a multiple main method in the same class?

no


What is a driver class in Java?

The driver class is often the class that contains the "Main" method.


Why main method is static?

Main method in java is always static as main method id the only method from where the program execution starts,and as we all know that main method is defined inside a class so JVM needs to make a object of the class to call the method and objects are build inside the main method ,so to execute the main method it has to make objects of the class but objects are build inside main method so that's the reason that main method is static so that JVM can execute the main method without making its object as static members can be called by class anme only


Can the main method call the other method if it is not defined as static?

No