code: public void leaveGroup(InetAddress mcastaddr) throws IOException {
          if (isClosed()) {
              throw new SocketException("Socket is closed");
          }
  
          checkAddress(mcastaddr, "leaveGroup");
          SecurityManager security = System.getSecurityManager();
          if (security != null) {
              security.checkMulticast(mcastaddr);
          }
  
          if (!mcastaddr.isMulticastAddress()) {
              throw new SocketException("Not a multicast address");
          }
  
          getImpl().leave(mcastaddr);
      }
docs: Leave a multicast group. Its behavior may be affected by
  {@code setInterface} or {@code setNetworkInterface}.
  
  <p>If there is a security manager, this method first
  calls its {@code checkMulticast} method
  with the {@code mcastaddr} argument
  as its argument.
  
  @param mcastaddr is the multicast address to leave
  @exception IOException if there is an error leaving
  or when the address is not a multicast address.
  @exception  SecurityException  if a security manager exists and its
  {@code checkMulticast} method doesn't allow the operation.
  
  @see SecurityManager#checkMulticast(InetAddress)