Calling a Method in Java


Here is the sample Java code that demonstrate how to call a method that is available in a non-main Class.

File:demo1.java

class dem
{
void get()
{
System.out.println(“Hi! Welcome”);
}
void show()
{
System.out.println(“Thanks”);
}
}
class demo1
{
public static void main(String a[])
{
dem d=new dem();
d.get();
d.show();
}
}

Here is the Output:

Hi! Welcome

Thanks

Share your comments and queries

Advertisements

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