-2

I read in SCJP6 that an abstract class cannot be instantiated. But read somewhere that they can be instantiated. Is is true? I am new to Java and would like if anyone could explain this in detail. An example would also be a good.

Yogesh D
  • 1,558
  • 14
  • 29
  • Also: http://stackoverflow.com/questions/30125552/does-the-jvm-internally-instantiate-an-object-for-an-abstract-class/30125593#30125593 – T.J. Crowder May 10 '15 at 06:23

2 Answers2

1

From the Java documentation:

Abstract classes cannot be instantiated, but they can be subclassed.

Abstract classes are similar to interfaces. You cannot instantiate them...

Community
  • 1
  • 1
Ori Lentz
  • 3,668
  • 6
  • 22
  • 28
1

You can create a reference of an abstract class, but cant instantiate it. For eg.

public abstract class AbstractClass {

    public abstract void abstractMethod();
    public  void concreteMethod(){
        System.out.println("am in concreteMethod");
    }

}

public class ExtndClass extends AbstractClass{

    @Override
    public void abstractMethod() {
        // TODO Auto-generated method stub
        System.out.println(" am in extended class");
    }
    public static void main(String...arg){
        AbstractClass abs = new ExtndClass();
        abs.abstractMethod();
        abs.concreteMethod();

    }

}

Output:

am in extended class
am in concreteMethod
Saurabh Jhunjhunwala
  • 2,832
  • 3
  • 29
  • 57