My problem is with a Polymorphic method , getSalary (which should be of type double. The problem is that the salary in this case depends on the average mark of a student and thus I felt the need for an If Statement because of the 2 conditions.
However java does not seem to allow 2 returns in the same method and considers the following code as not having a return statement.

    @Override
    double getSalary()
    {
        int avg=average(); //average is just a method which returns an average of an array of numbers

        if (avg>=50) 

            return 150.00;

        else if (avg<=50) 

            return 80.00;

    }

Thanks in advance for any help and hints in how I can implement this.

However java does not seem to allow 2 returns in the same method

That's not correct.

and considers the following code as not having a return statement.

This is correct. Not all paths end in a return statement, so your compiler is complaining. You have a return for the if clause, one for the else if clause, but no return for the implicit else clause. It doesn't matter that the implicit else clause is logically impossible, your compiler isn't checking the conditions, only the paths.

In this case you can turn the else if into a simple else to fix the problem, because that wouldn't break your logic.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.