What is a Java Class?
There are two kinds of classes in Java. Concrete vs Abstract Classes
Characteristics of Concrete Classes
- Concrete Classes in Java, means they can be instantiated. Unless, a private access modifier has been added to the constructor within that class.
Characteristics of Abstract Classes
- Abstract Classes in Java, means the can not be instantiated.
Simply stated, a class in java is made up of a few parts. These parts consist of the following:
- Variables – A type of container that holds a value of a particular data type.
- Methods – Here is where the logic of your code and algorithms live
HelloWorld Example:
This class below declares a variable ‘message’ with a data type of String. (We will discuss data types in a later section). It then has a method called ‘printMessage’ wich prints the message that is passed out to the console.
public class HelloWorld {
String message = "Hello World";
public void printMessage(String message) {
System.out.println(message);
}
}
Console Output: Hello World