Calling a Method without an Object


Demonstration of calling a method in java without creating an object of that class.

File:demo2.java

class dem
{
static void get()
{
System.out.println(“Hi! Welcome”);
}
static void show()
{
System.out.println(“Thanks”);
}
static void appear(int a)
{
System.out.println(“The Value is ” +a);
}
}
class demo2
{
public static void main(String a[])
{
get();
show();
appear(12);
}
}

Output:

Hi! Welcome

Thanks

12

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