• Post Reply Bookmark Topic Watch Topic
  • New Topic

missing return statement }  RSS feed

 
Dan Java
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Newbie problem. Get below error.

# javac CheckingAndSavingsOutputDemo.java
CheckingAndSavingsOutputDemo.java:19: missing return statement
}
^
1 error



//first of two classes

class Checking
{
// field
double balanceOfChecking = 0.0;

// parameterized constructor
Checking(double balanceOfChecking)
{
// assign value of formal variable to field, weight refers to the field above
this.balanceOfChecking = balanceOfChecking;
}

// define a method
double getBalance()
{
System.out.println("My checking account has " + balanceOfChecking + ".");
}
} <<<<<<<<<<<<<<<<< error here at line 19

Thanks!
Dan

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

The error message tells you exactly what's wrong. You've declared that the method should return a value of type double, but you're not returning anything (with a return statement) from the method.

Either change the return type to void (which means that the method doesn't return a value) or add a return statement that returns a value of type double.

For more information on writing methods, see Defining Methods and Returning a Value from a Method in Oracle's tutorials.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!