Can you add a constructor to an abstract class
We can create constructor in abstract class , it does’nt give any compilation
error.
Can you add a constructor to an abstract class
We can create constructor in abstract class , it does’nt give any compilation
error.
abstract class java constructor
/**
* Simple Java program to prove that abstract class can have constructor in Java.
* @author http://java67.blogspot.com
*/
public class AbstractConstructorTest {
public static void main(String args[]) {
Server server = new Tomcat("Apache Tomcat");
server.start();
}
}
abstract class Server{
protected final String name;
public Server(String name){
this.name = name;
}
public abstract boolean start();
}
class Tomcat extends Server{
public Tomcat(String name){
super(name);
}
@Override
public boolean start() {
System.out.println( this.name + " started successfully");
return true;
}
}
Output:
Apache Tomcat started successfully
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us