Online Java Compiler By
JavaTpoint.com
import java.net.HttpCookie; public class JavaHttpCookieSetDomainExample2 { public static void main(String[] args) { HttpCookie object1 = new HttpCookie("Parent1", "1"); HttpCookie object2 = new HttpCookie("Parent2", "2"); // Specifies the domain through which the cookie can be presented. object1.setDomain("www.localhost.com"); object2.setDomain("www.google.com"); System.out.println("The first domain name is given as: "+object1.getDomain()); System.out.println("The second domain name is given as: "+object2.getDomain()); } }
Output