• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

invoking classes

 
Adrienne Peck
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm working with a class (class a) that has code with constructors and methods (code x). these same constructors and methods are in another class (class b). i was told to invoke class b so that class invokes class b instead of running code x.

my cobol days taught me how to call one program from another program. i'm not sure of the syntax to invoke one class from another class.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm sure you've done it already: for example,

System.out.println("hi");

Here, "System.out" is a static member variable -- an instance of class java.io.PrintStream -- and "println" is a method in that class.

So all you need is an instance of the other class, and then you can call its methods. I don't know the details of your specific classes, of course, but generally, this might look something like (in class "a"):

b myB = new b();
myB.x();
 
Adrienne Peck
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you don't "invoke a class", you invoke methods on an instance of a class (= on an object).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic