• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Core Java Problem - Multilevel inheritance ,variable access

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class A
{
int i=10;
}


public class B extends A
{
int i=20;
}

public class C extends B
{
int i=30;

public void display()
{
System.out.println(this.i); // This line will print 30
System.out.println(super.i); // This line will print 20

System.out.println(); // i want to access int i of class A
}
public static void main(String args[])
{
C objc = new C();
objc.display();
}
}



How to access variable "i" of class A , in display method of class C.


Please can anyone tell me.
 
Sheriff
Posts: 7413
1423
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Casting would be helpful

System.out.println(((A)this).i);
 
Amol Pingate
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you

it's working...........
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The Sun Certification Results forum is meant for people to post messages when they have done a Sun certification exam - it is not for asking questions about Java. I will move this topic to a more appropriate forum for you. Next time, please select the appropriate forum yourself.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi dude, if you not fix with this problem Multilevel Inheritance

If you see this video which clearly explain you about the concept of "Multilevel Inheritance" in Java

http://www.youtube.com/watch?v=MA7-r83gat4

All the Best!!!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gopivista wrote:



Please check your private messages for an important administrative matter.
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amol please Use Code Tags when you post a source code. You can edit your message using this button ...
 
reply
    Bookmark Topic Watch Topic
  • New Topic