Function overloading and return type

Function overloading and return type


For example, the following program C++ and Java programs fail in compilation.
C++ Program
int DESCRIBE() {
    return 10;
}
 
char DESCRIBE() {  // compiler error; new declaration of DESCRIBE()
    return 'a';
}
 
int main()
{
    char x = DESCRIBE();
    getchar();
    return 0;
}
Java Program
// filename Main.java

public class Main {
    public int DESCRIBE() {
        return 10;
    }
    public char DESCRIBE() { // compiler error: DESCRIBE() is already defined
        return 'a';
    }
    public static void main(String args[])
    {

    }
}

Comments

Popular posts from this blog

Validate Mobile Number with 10 Digits in ASP.Net