Need help with a program.

Discussion in 'Java' started by yanamandra, Aug 20, 2012.

  1. yanamandra

    yanamandra Guest

    From: yanamandra <>

    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 + "}");

    }
    }
    =========

    --- 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
    #1
    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:
    389
    Kevin Spencer
    Jun 21, 2005
  2. pipi
    Replies:
    1
    Views:
    617
    Joseph Millar
    Jul 21, 2003
  3. Replies:
    1
    Views:
    470
    Walter Roberson
    Aug 12, 2005
  4. Replies:
    66
    Views:
    1,175
    Kenny McCormack
    Jun 18, 2006
  5. Kris Stark
    Replies:
    1
    Views:
    96
    John Bokma
    Sep 8, 2005
Loading...

Share This Page