How To Deal With A Constructor In An Abstract Java Class Code Example

Snippet 1

 * Simple Java program to prove that abstract class can have constructor in Java.
 * @author
public class AbstractConstructorTest {

    public static void main(String args[]) {
       Server server = new Tomcat("Apache Tomcat");

abstract class Server{
    protected final String name;
    public Server(String name){ = name;
    public abstract boolean start();

class Tomcat extends Server{
    public Tomcat(String name){

    public boolean start() {
       System.out.println( + " started successfully");
       return true;

Apache Tomcat started successfully


Copyright © Code Fetcher 2020




Leave a comment

Your email address will not be published. Required fields are marked *