0% found this document useful (0 votes)
9 views1 page

Java Classes Interaction Example

The document shows an example of using multiple classes and methods with parameters in Java. The Apples class contains the main method that creates an instance of the tuna class and calls its simpleMessage method. For the second example, the simpleMessage method in the tuna class now takes a String parameter, and the Apples class gets user input to pass to this method.

Uploaded by

azimasz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Java Classes Interaction Example

The document shows an example of using multiple classes and methods with parameters in Java. The Apples class contains the main method that creates an instance of the tuna class and calls its simpleMessage method. For the second example, the simpleMessage method in the tuna class now takes a String parameter, and the Apples class gets user input to pass to this method.

Uploaded by

azimasz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Multiple Classes

Apples class

class Apples {
public static void main (String args[])
{
tuna tunaObject = new tuna();
[Link]();
}
}
Tuna class

public class tuna {


public void simpleMessage(){
[Link]("This is another class");
}
}

Use Methods with Parameters

Apple class

import [Link];

class Apples {
public static void main (String args[])
{
Scanner input = new Scanner([Link]);
tuna tunaObject = new tuna ();

[Link]("Enter your name here: ");


String name = [Link]();

[Link](name);
}
}

Tuna class

public class tuna {


public void simpleMessage(String name){
[Link]("Hello " + name);
}
}

You might also like