Monday, July 27, 2009

Java compiler error question?

Assume that the class Pop is a subclass of the


class Drink. Assume that each class has a


constructor that takes a single String argument.


Which ONE of the following code segments


generates a compiler ERROR:


a.


Pop aPop;


Drink aDrink;


aDrink = new Pop("Coke");


b.


Pop aPop;


Drink aDrink;


aPop = new Pop("Orange Juice");


c.


Pop aPop;


Drink aDrink;


aDrink = new Drink("Pop");


d.


Pop aPop;


Drink aDrink;


aPop = new Drink("Coke");

Java compiler error question?
d will give compiler error. A subclass can assume the role of a parent class but not the other way round.
Reply:may be A.


cos parent class can't look into child class


No comments:

Post a Comment