Java #45:How to Print from another Class in Java [Program has 2 Classes]

———–Source Code——————-

//Programmer: Akinwale Owi
//Company: Dagba Computers
//Program Purpose: Create and print from multiple classes in a program

package dagbacomputers;

/**
*
* @author Akin
*/

public class DagbaComputers {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
meals menu= new meals();

//Printing breakfast
menu.breakfast();

//Printing Lunch
menu.lunch();

//Printing dinner
menu.dinner();

}//End of Main
}//End of DagbaComputers Class

class meals
{
//Constructor
meals()
{
System.out.printf(“My meals of the day:” + “\n”);
}//End of Constructor

//Breakfast Method
void breakfast ()
{
System.out.printf(“1.Breakfast was a bowl of cheerios” + “\n”);
}//End of breakfast method

//Lunch Method
void lunch ()
{
System.out.printf(“2.Lunch was a bacon burger” + “\n”);
}//End of lunch Method

//Dinner Method
void dinner ()
{
System.out.printf(“3.Dinner was lobster” + “\n”);
}//End of dinner method
}//End of meals classs

———–End of Program—————-

—————-Output——————-

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: