What are Custom/reference Data Types in java

Custom/reference Data Types in java >

  • Custom data types are created by defining and calling constructors of the class.
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{

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
//start paginationJs //end paginationJs