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.
Asked
Active
Viewed 524 times
2 Answers
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...
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