Create Class Inheritance - Java Object Oriented Design

Java examples for Object Oriented Design:Inheritance

Description

Create Class Inheritance

Demo Code

public class Main {
  public static void main(String[] args) {
    Manager mgr = new Manager();
    mgr.setName("Ana Bates");

    // Get the name of the manager
    String mgrName = mgr.getName();

    // Display the manager name
    System.out.println("Manager Name: " + mgrName);
  }/*from  www .  j a va  2 s.  c o  m*/
}
class Employee {
  private String name = "Unknown";

  public void setName(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }
}
class Manager extends Employee {   
  // No code is needed for now
}

Result


Related Tutorials