Frage im Vorstellungsgespräch bei Vanguard

What is Polymorphism? Steps on how to connect to a server using Java?

Antwort im Vorstellungsgespräch

Anonym

17. Mai 2016

Method overloading would be an example of static polymorphism. whereas overriding would be an example of dynamic polymorphism. Because, in case of overloading, at compile time the compiler knows which method to link to the call. However, it is determined at runtime for dynamic polymorphism. Connected with web server by using sock.getInetAddress() method of net.Socket class. import java.net.InetAddress; import java.net.Socket; public class WebPing { public static void main(String[] args) { try { InetAddress addr; Socket sock = new Socket("www.javatutorial.com", 80); addr = sock.getInetAddress(); System.out.println("Connected to " + addr); sock.close(); } catch (java.io.IOException e) { System.out.println("Can't connect to " + args[0]); System.out.println(e); } } }

3