This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread 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 Murach's Java Servlets and JSP this week in the Servlets 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
It is sorta covered in the JavaRanch Style Guide.
subject: Parent/Child
Similar Threads
Order of Execution(Interesting)-:)
want to know the order of execution?
Static Method and Inheritence.
can private methods be overridden?
explain the concept of data hiding