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 ???
About Question com.enthuware.ets.scjp.v6.2.604 :
Moderator: admin
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.604 :
You can't instantiate an abstract class but you can instantiate an anonymous class that extends the abstract class as follows:
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.
Code: Select all
Calculator x = new Calculator(){
public void calculate(){ }
};
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.604 :
BTW, in this question, nowhere is the Calculator class being instantiated.
-
- Posts: 1
- Joined: Tue Aug 26, 2014 11:44 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.604 :
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.
Who is online
Users browsing this forum: No registered users and 10 guests