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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

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

Post 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 ???

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

BTW, in this question, nowhere is the Calculator class being instantiated.

Matruim
Posts: 1
Joined: Tue Aug 26, 2014 11:44 pm
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests