If the class Chair is abstract public abstract class Chair o
If the class Chair is abstract: public abstract class Chair {//other code... public Chair() {//other code...}//other code...} would the following line compile (in main, or another part of the program): Chair newChair = new Chair(); True False
Solution
Answer ) False
Example Program :
import java.io.*;
public abstract class Chair
{
public Chair()
{
System.out.println(\"This is the abstract class\");
}
}
class TestAbstract
{
public static void main(String args[]){
Chair newChair = new Chair(); // Here we are try to instantiating the abstract class by creating the object
}
}
Output: Error message is displayed
Here we save the file as Chair.java
If we try to execute above code then it shows an Error message called \" Chair is abstract class cannot be instantiated \"
