Advertisement
KuoHsiangYu

MainClass.java

Jan 3rd, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. /* Java OCA 考題1 */
  2. class Super {
  3.  
  4.     int a = 10;
  5.  
  6.     public void show() {
  7.         System.out.println("Super class");
  8.         System.out.println("a = " + a);
  9.     }
  10. }
  11.  
  12. class Sub extends Super {
  13.  
  14.     int a = 50;
  15.  
  16.     @Override
  17.     public void show() {
  18.         System.out.println("Sub class");
  19.         System.out.println("a = " + a);
  20.     }
  21. }
  22.  
  23. public class MainClass {
  24.  
  25.     public static void main(String[] args) {
  26.         Super s1 = new Sub();
  27.         System.out.println("s1.a = " + s1.a);
  28.         System.out.printf("\n");
  29.         s1.show();
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement