Advertisement
KuoHsiangYu

JavaInheritanceTest1

Dec 14th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. package com.sample2;
  2.  
  3. class Father {
  4.     public int num1 = 0;
  5.     public int num2 = 0;
  6.  
  7.     public void show() {
  8.         System.out.printf("num1=%d, num2=%d\n", num1, num2);
  9.     }
  10. }
  11.  
  12. class Son extends Father {
  13.     public void setNum(int a1, int a2) {
  14.         num1 = a1;
  15.         num2 = a2;
  16.     }
  17. }
  18.  
  19. public class JavaInheritanceTest1 {
  20.     public static void main(String[] args) {
  21.         Son son = new Son();
  22.         son.setNum(10, 20);
  23.         son.show();
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement