oop - In Java, how do I call the method of a overridden class from an instance of the overriding class -


i new java inheritance. please see code parent class called term:

public class term {    public string value;   public void setvalue(string value)   {     this.value=value;   }    public string getvalue()   {     return value;   }  } 

now class operatorterm extends term

public class operatorterm extends term {    public static operator type;    public static boolean equals(string value)   {     string regex="(\\++)|(-+)|\\*|/";     boolean isoperand=value.matches(regex);     return isoperand;   }    public void assigntype(string value)   {     if(value.equals("+"))       type=operator.add;     else if(value.equals("-"))       type=operator.subtract;     else if(value.equals("*"))       type=operator.multiply;     else if(value.equals("/"))       type=operator.divide;     else if(value.equals("++"))       type=operator.increment;     else       type=operator.decrement;     }   } 

i creating operatorterm object in class:

public static term getterm(string termvalue) {   term newterm=null;   if(valueterm.equals(termvalue))     newterm=new valueterm();   else if(referenceterm.equals(termvalue))     newterm=new referenceterm();   else if(operatorterm.equals(termvalue))   {     newterm=new operatorterm();   }   return newterm; } 

in last elseif statement, want following newterm.assigntype. assigntype method in operatorterm class not present in term class. unable so, , wondering if can guide me on how can use newterm access methods of operatorterm class

i creating object of overridden class using

    else if(operatorterm.equals(termvalue))     {         operatorterm newoperatorterm = new operatorterm();         newoperatorterm.assigntype(...);         newterm = newoperatorterm;     } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -