Instantiating objects
After running the above code, you will not find any output. Rather, you may get an error message saying "No Main Class Found". This occurs since all Java
programs must have a main
method where the program will start. The Keyboard
class, however, should not have a main
method, so we will create another class named Main
inside a new file called Main.java
and run it.
We somehow need to use that class (blueprint) file to create different kinds of keyboards. The process of creating a real object from a class is called object instantiation. In Java, we can instantiate an object using the new
keyword.

xxxxxxxxxx
14
public class Main {
public static void main(String[] args) {
// Instantiating an Integer
Integer num = new Integer(10);
// Similarly Instantiating a keyboard
Keyboard keyboard = new Keyboard();
// Writing to a properties of that instance
keyboard.num_keys = 26
// Accessing properties
System.out.println(keyboard.num_keys);
// Calling methods
keyboard.sendSignal('a');
}
}
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment