We help IT Professionals succeed at work.

Inheritance+correct instance of the class

pret32
pret32 asked
on
Class HTMLPageBuilder inherits after PageBuilder (abstract class).
Class PageBuilder is associated with a FormPage class, so in FormPage class there is an attribute :

public PageBuilder thePageBuilder;

In one of the methods of the class, the attribute is instanciated as follows:

thePageBuilder=new HTMLPageBuilder();

During compilation I get an error, because further in the code thePageBuilder object uses the methods from HTMLPageBuilder class, which there are not in PageBuilder class.

FormPage.java:63: cannot resolve symbol
symbol  : method getXSL  ()
location: class XmlVer.PageBuilder
       thePageBuilder.getXSL();
                     ^
Comment
Watch Question

CERTIFIED EXPERT

Commented:
You'll have to either cast to HTMLPageBuilder prior to invoking the HTMLPageBuilder methods or simply store thePageBuilder as an HTMLPageBuilder in the first place.

If thePageBuilder reference is of the PageBuilder class, the compiler will only allow you to invoke methods on the explicit class.

Author

Commented:
cast like this:
(HTMLPageBuilder)thePageBuilder.getXSL();

???

Author

Commented:
It says: not a statement!!!!!
How to cast it ?

Author

Commented:
It says: not a statement!!!!!
How to cast it ?

Try: ((HTMLPageBuilder) thePageBuilder).getXSL ();

HTH

--Steve

Explore More ContentExplore courses, solutions, and other research materials related to this topic.