Holey_yan

[Java] 20151008_Inheritance

Oct 8th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. /***************************************/
  2. /** 20151008 Inheritance              **/
  3. /** Maker  : Yan                      **/
  4. /** E-Mail : [email protected] **/
  5. /** Date   : 2015/10/08 am.11:30      **/
  6. /***************************************/
  7.  
  8. public class Main {
  9.  
  10.     public static void main(String[] args) {
  11.         vector v1 = new vector();
  12.         v1.InValue1(10, 20);
  13.  
  14.         System.out.printf("X1 = %3d, Y1 = %3d\n",
  15.                 v1.GetX1(), v1.GetY1());
  16.  
  17.         vectors v2 = new vectors();
  18.         v2.InValue1(100, 200);
  19.         v2.InValue2(300, 400);
  20.         System.out.printf("X1 = %2d, Y1 = %2d\nX2 = %3d, Y2 = %3d\n",
  21.                 v2.GetX1(), v2.GetY1(),
  22.                 v2.GetX2(), v2.GetY2());
  23.     }
  24. }
  25.  
  26. class vector {
  27. protected
  28.     int x1;
  29.     int y1;
  30. public
  31.     void InValue1(int inX, int inY) { x1 = inX; y1 = inY; }
  32.     int GetX1() { return x1; }
  33.     int GetY1() { return y1; }
  34. }
  35.  
  36. class vectors extends vector {
  37. private
  38.     int x2;
  39.     int y2;
  40. public
  41.     void InValue2(int inX, int inY) { x2 = inX; y2 = inY; }
  42.     int GetX2() { return x2; }
  43.     int GetY2() { return y2; }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment