How to cast a string to an URL in java? -
my java code below.i wrote url=url(s); not true.i want make casting operation convert string taken user ,to url.how can operation?is there method this?
public static void main(string[] args) { system.out.println("welcome download manager"); url url; string s; scanner scan= new scanner(system.in); s=scan.nextline(); url=url(s); download download=new download(url); }
you can't cast string url, since string not subclass of url. can create new instance of url, passing string argument constructor. in java, always invoke constructor using keyword new:
url url = new url(string);
Comments
Post a Comment