27 July 2016

Tính kế thừa Extends (inheritance) trong Java

Inheritance in Java - Kế thừa trong Java (Extends)
Java 2016
package Demo26;

class A {
 int a=0;
}

class B extends A {
 float b=4;
}

class C extends B {
 double c=5.5;
}

class D extends C {
 String d="7";
}

class Test{
 public static void main(String args[]) {
  D d = new D();
  System.out.println(d.a);
  System.out.println(d.b);
  System.out.println(d.c);
  System.out.println(d.d);
 }
}
Output:
0
4.0
5.5
7

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang