Re: Need help with a program.

Discussion in 'Java' started by Leif Roar Moldskred, Aug 20, 2012.

  1. To: yanamandra
    From: Leif Roar Moldskred <>

    yanamandra <> wrote:
    > Why does the function printall() print the base class (c1) member
    > values? If that is reasonable, what is the method to print the
    > extended class (cls) values using the base class function printall().


    I take it school's back in session? The issue you're running into is called
    variable shadowing. Reading up on that should give you the answer to your
    problem.

    --
    Leif Roar Moldskred

    --- BBBS/Li6 v4.10 Dada-1
    * Origin: Prism bbs (1:261/38)
    --- Synchronet 3.16a-Win32 NewsLink 1.98
    Time Warp of the Future BBS - telnet://time.synchro.net:24
    Leif Roar Moldskred, Aug 20, 2012
    #1
    1. Advertising

  2. Leif Roar Moldskred

    yanamandra Guest

    To: Leif Roar Moldskred
    From: yanamandra <>

    On Monday, August 20, 2012 3:11:28 PM UTC+5:30, Leif Roar Moldskred wrote:
    > yanamandra wrote: > Why does the function printall() print the base class

    (c1) member > values? If that is reasonable, what is the method to print the >
    extended class (cls) values using the base class function printall(). I take it
    school's back in session? The issue you're running into is called variable
    shadowing. Reading up on that should give you the answer to your problem. --
    Leif Roar Moldskred

    But, variable shadowing is about the instance and local || local and scope
    specific. I have read the articles again after you asked me too. No luck on the
    exact problem I am mentioning.

    I am talking about inherited variables. there is i1, i2 and i3 in the super
    class with a method printall. there are the same 3 variables in the derived
    class but there is no printall method in the sub class. When printall() is
    invoked from the derived class's object, it still prints the super-class's
    values.

    And, if this is reasonable, what is the method by which I can get: 40, 50 and
    60 as the output from printall() when I invoke it using a derived class's
    object?

    -Venu

    --- BBBS/Li6 v4.10 Dada-1
    * Origin: Prism bbs (1:261/38)
    --- Synchronet 3.16a-Win32 NewsLink 1.98
    Time Warp of the Future BBS - telnet://time.synchro.net:24
    yanamandra, Aug 20, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wrecker
    Replies:
    3
    Views:
    376
    Kevin Spencer
    Jun 21, 2005
  2. pipi
    Replies:
    1
    Views:
    607
    Joseph Millar
    Jul 21, 2003
  3. Replies:
    1
    Views:
    457
    Walter Roberson
    Aug 12, 2005
  4. Replies:
    66
    Views:
    1,147
    Kenny McCormack
    Jun 18, 2006
  5. Kris Stark
    Replies:
    1
    Views:
    86
    John Bokma
    Sep 8, 2005
Loading...

Share This Page