So far the methods we wrote printed something to the console but did not return a value. In this lesson we create a class named Matematik and implement a topla method that takes two int parameters and returns their sum with return. You’ll see why Eclipse complains if a method with return type int has no return statement, how to store the result in a variable, then create an instance of Matematik, call the method, and two ways to print the returned value.
From Scratch Spring Boot series Episode 5 is available on the Opendart Akademi YouTube channel. This series is prepared from the recordings of our live Java Spring Boot course; we start from Java basics and progress toward Spring Boot.
▶ Watch the lesson on YouTubeAll episodes in the series
What’s in this lesson?
- 00:00 Introduction
- 00:03 What does a method that returns a value mean?
- 00:29 Creating the Matematik class
- 01:20 Method definition: access modifier, return type (int), name, parameters
- 02:14 "This method must return a result of type int" error
- 02:44 The return statement
- 03:27 Storing the result in a variable and returning it
- 04:34 Creating an object to use the method
- 05:40 new Matematik object
- 06:37 topla(5, 5): calling the method with parameters
- 07:04 Assigning the returned value to a variable and printing it
- 07:58 Trying different values
- 08:09 Closing
Opendart Akademi
Learn Spring Boot with an instructor in live lessons
These videos are recordings from our Java Spring Boot course. The full course covers Java, Spring Boot, REST APIs, databases, and real projects; you can ask the instructor when you get stuck.
← Previous lesson: How to Debug in Eclipse? Step Through Code with Breakpoints · Playlist: From Scratch Spring Boot · Subscribe on YouTube
Instructor: İbrahim Gökyar (Opendart Akademi)



