The Anatomy of a Java Class
Learn how to write a class in Java.
We'll cover the following...
We'll cover the following...
Back in Unit 2, we learned how to use classes and objects. Now, we’ll dive deep into classes and object-oriented programming.
Let’s begin by learning how to create our own Java class.
For every data type, we have a separate class. When we create objects, we are creating instances of a class. In other words, we are creating variables of type class. We’ve made many String
variables by now. They store the references of String
objects.
Designing a class
Look at the steps below to learn how to create a basic structure of a class:
A class is like a blueprint. Consider the example below.
/* Blueprint of Employee class*/
public class Employee
{
// class definition
}
/* Objects of Employee class*/
Employee e1 = new Employee();
Employee e2 = new Employee();
Suppose a company needs to keep a record of its employees. The company can’t survive ...