Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Need help with a program.

Reply
Thread Tools

Need help with a program.

 
 
yanamandra
Guest
Posts: n/a
 
      08-20-2012
From: yanamandra <(E-Mail Removed)>

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/3
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help, I am intermediate in Java...need help in follow case ElementX Java 9 10-01-2008 08:02 PM
Help Help. I really need some help with this =?Utf-8?B?Q2hyaXM=?= ASP .Net 3 01-31-2007 09:33 PM
re_---need help Network Adapters!!!! NEED HELP!!!! hedayatniac@gmail.com Computer Support 4 08-13-2006 01:03 AM
Need help! I need to add lead zeros to a textbox Teep ASP .Net 2 06-21-2004 01:04 PM
Please help!!! Need datagrid selection to fill textboxes...Need quick!! TN Bella ASP .Net 1 06-18-2004 01:31 AM



Advertisments