A Basic Program in Java
A basic program in Java will have at least the following components:
- Classes and Objects
- Variables
- Methods
xxxxxxxxxx
27
// Class
class Node {
// Variables
int data;
Node next;
// Method
Node() {}
// Method
public Node(int data, Node next) {
this.data = data;
this.next = next;
}
}
public class Main {
public static void main(String[] args) {
// Object
Node node = new Node();
System.out.println(node);
}
}
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment