This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes multiple inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "multiple inheritance " Watch "multiple inheritance " New topic
Author

multiple inheritance

nagu datla
Greenhorn

Joined: Jan 27, 2008
Posts: 4
How to get the output 1,2,3 for the following code with out using constructors and only using super.


class a
{
int i=1;
}
class b extends a
{

int i=2;
}
class c extends b
{ int i=3;
void show()
{

System.out.println(super.i);
System.out.println(super.i);
System.out.println(i);
}
}
class demo3
{
public static void main(String args[])
{
c ob=new c();
ob.show();
}
}
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38057
    
  22
We don't answer that sort of question. Tell us what you have tried and whether it works and what you think has gone wrong.
Andre Brito
Ranch Hand

Joined: Dec 13, 2007
Posts: 95

I guess that without accssor methods for the variables you can't. And those methods must have different names, 'cause if you use only the getI() it'll override the superclass methods and you can't access variables...

BTW, code too the publics and privates word. It's a good software engeneering practice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multiple inheritance
 
Similar Threads
Core Java Problem - Multilevel inheritance ,variable access
Super Class Question?
what is wrong ?
how to call parent class data
Need "super" keyword understanding