This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Parent/Child Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Parent/Child" Watch "Parent/Child" New topic


Mickey Atanasovic

Joined: Jan 31, 2003
Posts: 2
class Parent {
int i = 100;
void Printme() {
class Child extends Parent {
int i = 10;
void Printme() {
public class Class1 {
public static void main (String args[]) {
Parent p = new Child();
Output is :
On which way I can access variable i of the Child class.
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
Look for the answer here
Piotr Kaluski

Joined: Jan 31, 2003
Posts: 8
In addition to an answer given by R Manivannan, it is worth noting than you can access i in Child class using explicit cast:

Piotr Kaluski<br />SCJP 1.4
jQuery in Action, 2nd edition
subject: Parent/Child