Socket communication in Java enables communication between two endpoints over a network. There are two main types of sockets: TCP sockets and UDP sockets. Let's explain both types with examples: TCP Socket Communication: 1. **Server Side**: - The server creates a `ServerSocket` object to listen for incoming connections on a specific port. - When a client connects, the server accepts the connection and creates a `Socket` object to communicate with the client. - The server reads from and writes to the socket's input and output streams to communicate with the client. import java.io.*; import java.net.*; public class TCPServer { public static void main(String[] args) throws IOException { ServerSocket serverSocket = new ServerSocket(12345); System.out.println("Server started. Waiting for client..."); Socket clientSocket = serverSocket.accept(); System.out.println("Client connected."); BufferedReader in = new Bu
In Java, when a class inherits from another class, it inherits both the data members (fields or variables) and methods (functions or behaviors) of the parent class. This process is known as inheritance and is a fundamental concept of object-oriented programming. Inheriting Data Members: - Inherited data members include fields or variables declared in the parent class. - These data members are accessible in the subclass just like they are in the parent class. - Subclasses can use inherited data members directly or override them if necessary. Inheriting Methods: - Inherited methods include all the public and protected methods defined in the parent class. - Subclasses can use inherited methods directly, extend their functionality, or override them to provide custom implementations. - Private methods in the parent class are not inherited and are not accessible in the subclass. Example: Consider a simple example to illustrate inheritance in Java: // Parent class class Vehicle { String