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

Related Posts:

  • Ví dụ Servlet tính tổngServlet in java Enter number for loop  = sum TCPServer.java package network.sample; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.ServerSocket; import java.net… Read More
  • TCPServer TCPClient Display: Gui a Nhan97 Gui b Nhan98 Gui c Nhan99 Gui d Nhan100 Gui e Nhan101 Gui f Nhan102 Gui g Nhan103..... package network.sample; import java.io.IOException; import java.io.InputStream; import java.io.Out… Read More
  • UDPServer UDPClient Converting String to Int in Java? Integer x = Integer.valueOf(str); // or int y = Integer.parseInt(str); int foo = Integer.parseInt("1234"); UDPServer UDPClient Servlet package demo5; import java.net.DatagramPacket; i… Read More
  • StringClient StringServer package network.sample; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.net.Socket; public class StringClient { public static void main(String args[]) { try { … Read More
  • NumberClient NumberServer MVC: Model View Controller Design Patterns - MVC package network.sample; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.Socket; import java.util.Sca… Read More

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang