i want to override method with different return type is it possible?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Laxmikant Masuti
    New Member
    • Sep 2010
    • 2

    #1

    i want to override method with different return type is it possible?

    at the compile time it gives the error like
    "attempting to use the incompatible return type"
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    It means that the return value is assigned to some other data type or object.

    ex:
    Code:
    int x = getValue(val);
        //some code....
        public List getValue(int val){
           //some code...
        }
    Usage of codes like this will throw that error. Just check for whether the returned value and assigning variable type are same or not.

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • Dheeraj Joshi
      Recognized Expert Top Contributor
      • Jul 2009
      • 1129

      #3
      Method overriding means new method definition in subclass which is same as parent class. The signature of the class must be same(i.e method name,parameters and return type)

      Regards
      Dheeraj Joshi

      Comment

      • RamananKalirajan
        Contributor
        • Mar 2008
        • 608

        #4
        Sorry confused with overloading.

        Thanks and Regards
        Ramanan Kalirajan

        Comment

        Working...