Re: Core java fundamental help
- From: "krishna" <murali.medikonda@xxxxxxxxx>
- Date: 31 Aug 2006 04:03:05 -0700
pras.vaidya wrote:
Hello all , I am a newbie in java .Learning core java concepts and i
got confused with this piece of code . The output of code is "Extends
Super" . First time it prints Extends because of overriding but why it
prints " super" later.
Thanks in advance.
Code goes as follow
class SuperShow{
public String str ="Super";
public void show(){
System.out.println(str);
}}
class ExtendsShow extends SuperShow{
public String str = "Extend";
public void show(){
System.out.println(str);}
public static void main(String[]args){
ExtendsShow ext = new ExtendsShow();
SuperShow sup = ext;
sup.show();
//ext.show();
System.out.println(sup.str);
//System.out.println( ext.str);
}}
Hai friend, when you are calling sup.show() it displays
"Extend",because of overriding.ok you know it.your question is later
why it displays "super"?
Because you r printing (sup.str). so it displays
super class String i.e it displays
Super. when ever we call super class vars,constructors,methods by
using super class reference variable it displays super class members
only except if the sub class method overrides super class method it
executes subclass method only.if i am wrong please reply
the solution..byeeeeeeeee
.
- References:
- Core java fundamental help
- From: pras.vaidya
- Core java fundamental help
- Prev by Date: Re: Core java fundamental help
- Next by Date: Wish To Have Gold In Your Purse?Read...
- Previous by thread: Re: Core java fundamental help
- Next by thread: POJO Interface
- Index(es):