Execute Methods
Lesson 10 of 12 in Coddy's Basics of Classes and Objects in Java course.
To access methods in an object, we use:
MyClass myObj = new MyClass();
myObj.myMethod();In the above example, we execute the method called myMethod in the object myObj which is an instance of MyClass class.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
Challenge
EasyYou are given a code with a class named SecretMethod, in the main method, create an object for this class and call the secret method with the argument 5.
Try it yourself
class SecretMethod {
public void secret(int x) {
System.out.println(x + " is the secret!");
}
}
class Main {
public static void main(String[] args) {
// Write code here
}
}All lessons in Basics of Classes and Objects in Java
1Introduction
Introduction