Custom/reference Data Types in java >
Example - We may create employee class and define its constructor.
class Employee {
private Integer id;
/** Employee constructor*/
public Employee(Integer id) {
this.id = id;
}
}
/** Main class*/
public class MyClass {
public static void main(String...a) {
Employee emp; //emp is pointing to null
emp=new Employee(1); //emp is pointing to object
}
}
|
emp is reference variable of Employee type.
> emp can refer to any subClass of Employee as well
emp=new SubEmployee();
|
Where SubEmployee is subClass of Employee
class SubEmployee extends Employee{
SubEmployee(){
super(1);
}
}
|
Labels:
Core Java
core java Basics