Method overriding in java

As in C++, java as an OOP language supports method overriding

class getFullName
{
        public String get(String a,String b)
        {
        return a+" "+b;
        }
}
class methodOverriding extends getFullName
{
        public String get(String a,String b)
        {
        return a+"-"+b;
        }
      
        public static void main(String args[])
        {
System.out.println("get() from methodOverriding "+new methodOverriding().get("87J8","2KH8"));
System.out.println("get() from getFullName "+new getFullName().get("Gutha","Gowtham"));
        }
}
getFullName - get(String a,String b) : Takes two strings and returns them with a space between them
methodOverriding - get(String a,String b) : Takes two strings and returns them with a - between them

No comments: