A Test Class to Demonstrate field's Inheritances - Java Object Oriented Design

Java examples for Object Oriented Design:Inheritance

Description

A Test Class to Demonstrate field's Inheritances

Demo Code

class MySuper {//from w w  w  .  j av  a  2 s  .  co  m
  protected int num = 100;
  protected String name = "Edith";
}
class MySub extends MySuper {   
  public void print() {
    System.out.println("num: " + num);  
    System.out.println("name: " + name);  
  }  
}


public class Main {
  public static void main(String[] args) {
    MySub fhSub = new MySub();
    fhSub.print();  
  }
}

Result


Related Tutorials