Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #18168

Need help with a program.

From yanamandra <venu.yanamandra@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Need help with a program.
Date 2012-08-20 02:24 -0700
Organization http://groups.google.com
Message-ID <82bcd41c-df92-4103-b674-718cf64a999b@x8g2000yqf.googlegroups.com> (permalink)

Show all headers | View raw


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().


=========
class c1
{
  public static int i1;
  private static int i2;
  protected static int i3;


  c1()
  {
    i1 = 10;
    i2 = 20;
    i3 = 30;
  }

  protected void printall()
  {
    System.out.println("From C1: i1 is: {" + i1 + "}, i2 is: {" + i2 +
"} and i3 is: {" + i3 + "}");
  }
}

class cls extends c1
{
  public static int i1;
  private static int i2;
  protected static int i3;

  cls()
  {
    i1 = 40;
    i2 = 50;
    i3 = 60;
  }

/*

*/

  public static void main(String[] args)
  {
    cls cls1  = new cls();
    cls1.printall();

    c1 cls2 = cls1;
    cls2.printall();

    System.out.println("From CLS: i1 is: {" + i1 + "}, i2 is: {" + i2
+ "} and i3 is: {" + i3 + "}");

  }
}
=========

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Need help with a program. yanamandra <venu.yanamandra@gmail.com> - 2012-08-20 02:24 -0700
  Re: Need help with a program. Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-08-20 04:41 -0500
    Re: Need help with a program. yanamandra <venu.yanamandra@gmail.com> - 2012-08-20 02:57 -0700
      Re: Need help with a program. Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-08-20 05:16 -0500
        Re: Need help with a program. yanamandra <venu.yanamandra@gmail.com> - 2012-08-20 03:39 -0700
          Re: Need help with a program. Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-08-20 06:46 -0500
            Re: Need help with a program. yanamandra <venu.yanamandra@gmail.com> - 2012-08-20 04:58 -0700
          Re: Need help with a program. Lew <noone@lewscanon.com> - 2012-08-20 07:31 -0700
            Re: Need help with a program. Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-08-21 03:43 -0500
  Re: Need help with a program. Roedy Green <see_website@mindprod.com.invalid> - 2012-08-20 17:22 -0700

csiph-web