• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

extending another class but not working

 
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,


extended class is:


The main issue is SiteTemplateMethods requires a variable int langPref that exists in parent class SiteTemplate but how can I pass or inherit to SiteTemplateMethods class?

Best regards
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right now, your child class is implicitly calling super() with no parameters. Therefore it doesn't pass language to the superclass.
You need to invoke the SiteTemplateMethods constructor that takes the language as a parameter.
i.e.


You should probably get rid of the parameterless constructor in SiteTemplateMethods if it doesn't make sense to create one without the language being specified.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your prompt reply.

This is whole class that getting all methods from parent class SiteTemplateMethods


Now when I used super(lang); then its throwing following error in browser:


Furthermore, none of method written in SiteTemplateMethods is working properly because they are not getting int lang. When I remove extends SiteTemplateMethods and instatntiate class as:
SiteTemplateMethods stm = new SiteTemplateMethods(lang); and use stm.header() etc. then all works fine. why?

please adivse?
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us what is happening at Line 65 in your SiteTemplate?
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Harry wrote:Can you show us what is happening at Line 65 in your SiteTemplate?





there was a method on line 65 footer() that was exists in parent as well as in child class. I override the method and forget to user super keyword to call parent footer() method. When I used super.footer(); then all works fine

Thanks from the bottom of my heart. I always benefited in this forum. Can't have words to express my thanks

Best regards
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic