• 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

Unable to invoke super constructor as intended

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please note modified Sierra/Bates code, Chapter 2, Question 2



How do I make the output produce "DB". I thought that by executing new Bottom("C"), it would first create the superclass, i.e. Top, by invoking

public Top(String s) {System.out.print("B"); }

And then execute:

public Bottom(String s) { System.out.print("D"); }

Please clarify this concept. I've searched this forum and it discusses this same problem at another angle
 
Ranch Hand
Posts: 310
1
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you think will be inserted in Bottom(String s) { ... }? super() or super(String s) ???

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By default compiler puts super() !!! ie no argument constructor call to Super class.

Essentially , what compiler sees is the following


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

Rajeev Rnair wrote:What do you think will be inserted in Bottom(String s) { ... }? super() or super(String s) ???




I was under the impression that super(String s) would be inserted in Bottom(String s). Apparently, this is not the case...
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sandra Bachan wrote:How do I make the output produce "DB".



two ways are there
1. replace

with


2. replace

with
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Sandra,

What if we said that the ONLY constructor the compiler will build for you automatically is a no-arg constructor?

Would the code make sense then?

Bert
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bert Bates wrote:Hey Sandra,

What if we said that the ONLY constructor the compiler will build for you automatically is a no-arg constructor?

Would the code make sense then?

Bert



Was trying out the different ways to output BD. This most certainly makes sense.
 
Everybody's invited. Even this 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