Core java fundamental help



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);
}}

.



Relevant Pages

  • Re: Core java fundamental help
    ... if you create a class with "extends" then you override the methods, ... The output of code is "Extends ... public void show{ ... class ExtendsShow extends SuperShow{ ...
    (comp.lang.java.programmer)
  • Re: Thread doesnt interrupt!? HELP please
    ... I took a boolean "stopUpdate" as nos proposed to do. ... "isUpdating" to false. ... public class MyClass extends JFrame{ ... public void updateThumbs() { ...
    (comp.lang.java.programmer)
  • Re: Compiler bug? "reference to addAll is ambiguous"
    ... extends E>) in java.util.List<capture#420 ... super gov.sc.eip.report.birt.items.ChangeRow> match ... I assume E extends ChangeRow. ... public void addAll(Collection<? ...
    (comp.lang.java.programmer)
  • Re: Return pressed event
    ... > public class Frame1 extends JFrame implements ActionListener, ... public void actionPerformed ... Sun Certified Developer for the Java 2 Platform ...
    (comp.lang.java.programmer)
  • When will reflections support casting (especially for constructors, etc) properly?
    ... class B extends A ... public void foobar ... the class string "A" as a reference of the target typecast class. ... in this example) MUST be public (even if reflection code lives within ...
    (comp.lang.java.programmer)