🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: ibm.software.vajava.language
Article #4

How to make a member variable of a derivation read-only?

#4
From: Hannes Heckner
Date: Tue, 29 Feb 2000 00:00
52 lines
2133 bytes
Hi,

I tried to following example to have my member variable foo
read-only in the derivation:

public class Class1
{
	/**
	 * The main entry point for the application. 
	 *
	 * @param args Array of parameters passed to the application
	 * via the command line.
	 */
	public static void main (String[] args)
	{
		// TODO: Add initialization code here
		Base b = new Base();
		Derivation d = new Derivation();
		b.doFoo();
		d.doFoo();
	}
}

class Base 
{
	protected int foo = 0;
	
	public void doFoo()
	{
		System.out.println(""+foo);
	}
}

class Derivation extends Base
{
	final int foo = 1;
}



Unfortunately it seems that the Derivation class DOES NOT
overload foo! Therefore you will get the following output:
0
0

How can I make foo final in the derivation by OVERLOADING
foo from the Base class?

If you know a solution to this problem, please submit it to http://www.the-codebook.com/show_code.asp?ProblemId=1356

+++++++++++ Posted via The-Codebook.Com, The Source for Developers +++++++++++
http://www.The-Codebook.com/                      Java, VisualBasic, VisualC++
Technical Details
Message-ID: <951828737327@munich.ixos.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,d86be700aa9afbe6,start
X-Google-Attributes: gidf74b3,public
X-Google-Thread: 10a146,d86be700aa9afbe6,start
X-Google-Attributes: gid10a146,public
X-Google-Thread: fbe9c,d86be700aa9afbe6,start
X-Google-Attributes: gidfbe9c,public
X-Google-Thread: 100145,d86be700aa9afbe6,start
X-Google-Attributes: gid100145,public
X-Google-Thread: 114aa0,d86be700aa9afbe6,start
X-Google-Attributes: gid114aa0,public
X-Google-Thread: 113ae9,d86be700aa9afbe6,start
X-Google-Attributes: gid113ae9,public
From: Hannes Heckner <Hannes.Heckner@munich.ixos.de>
Subject: How to make a member variable of a derivation read-only?
Date: 2000/02/29
Message-ID: <951828737327@munich.ixos.de>
X-Deja-AN: 591303378
Organization: The-Codebook.Com
Mime-Version: 1.0
Newsgroups: ibm.software.vajava.language,borland.public.jbuilder.java.language,borland.public.jbuilder.java,microsoft.public.java.visualj++,comp.lang.java.help,comp.lang.java.programmer