I have a good idea what I am supposed to put but I can't seem to get it right. I have two different files, Server.java and Client.java. I want Client.java to call a method in Server.java. This is what I have figured out so far.

public class Client{
public static void main(String[] args) {
Server otherInstance = new Server();
otherInstance.instanceMethod();
Server.staticMethod();
}
}

I am a complete novice but I think I have to replace the word "other" with the method I am trying to use from the file, Server.java? Any help would be greatly appreciated.

Recommended Answers

All 6 Replies

public class Client{
public static void main(String[] args) {
Server otherInstance = new Server();
otherInstance.instanceMethod();
Server.staticMethod();
}
}

It looks like you created an Server object and used a method from Server.java, is that not what you want??????

It looks like you created an Server object and used a method from Server.java, is that not what you want??????

I want to use a method from Server.java in the file Client.java

I have a good idea what I am supposed to put but I can't seem to get it right. I have two different files, Server.java and Client.java. I want Client.java to call a method in Server.java. This is what I have figured out so far.

public class Client{
public static void main(String[] args) {
Server otherInstance = new Server();
otherInstance.instanceMethod();
Server.staticMethod();
}
}

I am a complete novice but I think I have to replace the word "other" with the method I am trying to use from the file, Server.java? Any help would be greatly appreciated.

No, you replace "instanceMethod" with the name of the method, unless it is declared to be a static method in Server, in which case you replace "staticMethod".

No, you replace "instanceMethod" with the name of the method, unless it is declared to be a static method in Server, in which case you replace "staticMethod".

Because the method is static do i delete the line,
otherInstance.instanceMethod();

If the method is static then you need to use the class name ex:

Server.instanceMethod();

If the method is static then you need to use the class name ex:

Server.instanceMethod();

Ok thank you. I figured it out. Too bad I didn't come here sooner because my assignment was due at 10 and it is now 11 :( oh well should have looked into the classwork sooner...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.