Create Objects
Lesson 8 of 12 in Coddy's Basics of Classes and Objects in Java course.
Now, to get the whole picture, let's learn about Objects!
As said before, object are instances of a class, and a class is a template for an object.
To create an object of a class, we use the new keyword:
MyClass myObj = new MyClass();In the above example, we create an object called myObj of type class MyClass.
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.
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 MyPoint, in the main method, create an object for this class and name it <strong>point</strong>.
Try it yourself
class MyPoint {
int x = 5;
int y = 10;
}
class Main {
public static void main(String[] args) {
// Write code here
// Don't change below this line
System.out.println("(" + point.x + ", " + point.y + ")");
}
}All lessons in Basics of Classes and Objects in Java
1Introduction
Introduction