P
pras.vaidya
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);
}}
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);
}}