Methods
Lesson 4 of 12 in Coddy's Basics of Classes and Objects in Java course.
You might already be familiar with methods from Methods in Java course (If not, you should do it!)
To create a method in class, use:
class MyClass {
public void myMethod() {
}
}In the above example, we create a class named MyClass with a method called myMethod that returns nothing (void).
Note the public keyword, it indicates the method can be accessed by objects, we won't access this topic in this course - but add it to all your methods.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
Challenge
EasyCreate a class named Sum with a method named calc that takes two arguments (integers) and returns the sum of the two numbers.
Try it yourself
// Write code here