Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.604 :

Posted: Sun Jun 24, 2012 4:15 pm
by ETS User
abstract class Calculator
{
abstract void calculate();
public static void main(String[] args)
{
System.out.println("calculating");
Calculator x = null;
x.calculate();
}
}


HOW IS ABSTRACT CLASS INSTANTIATED ???

Re: About Question com.enthuware.ets.scjp.v6.2.604 :

Posted: Sun Jun 24, 2012 4:50 pm
by admin
You can't instantiate an abstract class but you can instantiate an anonymous class that extends the abstract class as follows:

Code: Select all

Calculator x = new Calculator(){
                                public void calculate(){ } 
                             };
Same logic applies for an interface. So when you say you are instantiating an abstract class or an interface, it means you are actually instantiating an anonymous class that extends or implements the abstract class or interface.

Re: About Question com.enthuware.ets.scjp.v6.2.604 :

Posted: Sun Jun 24, 2012 4:57 pm
by admin
BTW, in this question, nowhere is the Calculator class being instantiated.

Re: About Question com.enthuware.ets.scjp.v6.2.604 :

Posted: Tue Aug 26, 2014 11:47 pm
by Matruim
I believe that the problem is that the Method is never overridden in a subclass and that the program will throw an exception to that effect.