This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thangaraj S. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic

Thangaraj S.

Thangaraj Selvamani
Ranch Hand

Joined: Sep 20, 2008
Posts: 61
Can any one give be the explanation for the code above and y it prints the output as parent

class Parent {
String message = "parent";
void say() {

class Child extends Parent {
String message = "child";


public class ScjpTest3 {
public static void main(String[] args) {
new Child().say();
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
Welcome to JavaRanch.

The way JavaRanch works is not just to give out answers, but to help people understand what's going on. So: What is the output, and why do you think that is? Where is it different from what you thought it would be? Can you think why?

We also have a collection of tips on how to get the most out of the Saloon: HowToAskQuestionsOnJavaRanch, in particular UseAMeaningfulSubjectLine.
Thangaraj Selvamani
Ranch Hand

Joined: Sep 20, 2008
Posts: 61
Sorry for the mistake... im new to this site...
here after i will give correct and reasonable title...

ya..i got the explanation for that code...
thanks for the links... will go through it...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15037

Double post

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
jQuery in Action, 3rd edition
subject: Thangaraj S.
It's not a secret anymore!