[Solved] Passing String from one class to another


There are two ways:

  1. create an instance of your printer class and evoke the method on the printer object:

    public class MyPrinter
    {
        public void printString( String string )
        {
            System.out.println( string );
        }
    }
    

in your main:

MyPrinter myPrinter = new MyPrinter();
myPrinter.printString( input );

or 2. you create a static method in your printer class and evoke it in your main:

public class MyPrinter
{
    public static void printStringWithStaticMethod(String string)
    {
        System.out.println(string);
    }
}

in your main:

MyPrinter.printStringWithStaticMethod( input );

solved Passing String from one class to another