473,839 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple extending

I have a class, let's call it "x". I have another class, y, which
extends x. Then I have a class z which extends y. There is a
function in y (but not in x) which I have overridden in z. But when I
try to run the program, it uses the version of the function in y! I
have heard that java doesn't support multiple inheritance, so could
this be the problem?

So basicall: is there a rule in java which I am violating by trying to
have a class extend a class extending a class? And if so, what can I
do to work around it?
Jul 17 '05 #1
2 3692
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

PlasmaDragon wrote:
I have a class, let's call it "x". I have another class, y, which
extends x. Then I have a class z which extends y. There is a
function in y (but not in x) which I have overridden in z. But when
I
try to run the program, it uses the version of the function in y! I
have heard that java doesn't support multiple inheritance, so could
this be the problem?

So basicall: is there a rule in java which I am violating by trying
to
have a class extend a class extending a class? And if so, what can
I do to work around it?


Hi,
No rules violated here, and this doesn't actually have to do with
multiple inheritance. Multiple inheritance means one class cannot
*directly* extend two classes. However, I'm not sure where your
problem comes from. Examine the following code, of my design:

- --- X.java ---
public class X {
public X() {
}
}
- --- Y.java ---
public class Y extends X {
public Y() {
super();
}

public void doSomething() {
System.out.prin tln("Something in Y.");
}
}
- --- Z.java ---
public class Z extends Y {
public Z() {
super();
}

public void doSomething() {
System.out.prin tln("Something in Z.");
}

public static void main(final String[] args) {
Y y;
Z z;

y = new Y();
y.doSomething() ;

z = new Z();
z.doSomething() ;

y = z;
y.doSomething() ;
}
}
- --- END OF FILES ---

Compiling the above files, then running as "java Z", produced the
expected output of:

Something in Y.
Something in Z.
Something in Z.

- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAf1Henwj A8LryK2IRAn+AAK DX6P45FSgv9wDYZ TzYatbbl4lVfwCb BX8n
3pX+QgK84LSyM/zNvyAienQ=
=Ab5x
-----END PGP SIGNATURE-----
Jul 17 '05 #2
I found the problem. The function I overrode in Z was called in Y by
another function, so it used the Y version. So I copied the caller
function into Z and the problem is solved.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4834
by: Gabriele Farina | last post by:
Hi, I'd like to manage multiple socket connection without having to use Threads. I'd like to manage every connection when it is returned from socket_Accept(), without having to wait for the current running tonnection to stop. How can I do that? bye
4
2795
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been working with Python for a year or more now, but only doing simple extending in C/C++. I'm now attempting some embedding and several questions have come to mind. BTW - I'm running Windows 2000 with Python23 and VisualC++ developers
1
5884
by: wireless | last post by:
We recently added a new database at the company. It has only one purpose - to hold massive amounts a daily data generated by telephone calls on a network. The amount of data was so large (several gigabytes a day) that the guy who set up the database creates a new table for it each day. His thinking was that if we only need to query one day's worth of data then it would be a lot faster to query a table with one day's data than having...
1
1735
by: Richard Townsend | last post by:
In the "Extending and Embedding" part of the Python documentation: section 5.4 "Extending Embedded Python" - it describes how to use a Python extension module from Python that is embedded in a C application. Is it safe to call Py_InitModule() more than once in the same application - in order to be able to use more than one extension module? -- Richard
4
3434
by: Matt | last post by:
Hi, I've been thinking about how to do this, but can't think of a solution. I have a class that is derived from System.Web.UI.WebControls.DataGrid which works a treat, but I'd like to extend the DataGridColumnCollection class (property of DataGrid) just a fraction by allowing a string indexer. i.e. rather than using myDataGrid.Columns.Visible = false;
5
3836
by: vbgunz | last post by:
Hello everyone. I own two books. Learning Python and Python in a nutshell. When cross referencing the two books to try and clarify the ideas behind extending methods and delegates, this is where confusion veered it's ugly head :( Learning Python explains on page 324: Class Interface Techniques (21.3.3 in the ebook) the following is an extender method. ''' #################################### '''
0
1570
by: vishnu | last post by:
Hello All, I have embedded python 2.5 in to my C application. As we need the python scripts to run in multi threaded environment I have used Py_NewInterpreter() and Py_EndInterpreter each time I execute a run script function. The code is as follows: RunScript(char *pScriptName,char *pFuncName,...) { PyEval_AcquireLock()
3
3679
by: katis | last post by:
Hi all :) Is it posible in xsd to change only minOccurs value of element in complex type by extending this type? The problem I'm trying to solve is this: I have two complex types - "TextField" and "FileChooser". Here is definition of "TextField" <xsd:complexType name="TextField">
5
2127
by: Wolfgang Hanke | last post by:
Hello, I want to extend multiple Controls like TextBox, Label, ComboBox etc. with the same new featureset (for Example all need a Method getSomething()) Because I cant alter their Base-Class I have to write one new class for each Control like MyTextBox, MyLabel, MyComboBox implementing IMyControlInterface. The Code for each Control is exactly the same but C# offers no way to "include" some code.
0
9697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10647
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10292
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7017
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4482
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3132
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.