Posted by : Unknown
Wednesday, 17 June 2015
Same class:
class oneclass
{
public void display()
{
System.out.println( "Welcome to Java!" );
}
}
public void display()
{
System.out.println( "Welcome to Java!" );
}
}
public class simpleclass
{
public static void main( String args[] )
{
oneclass one =new oneclass();
one.display();
}
}
Output:
Welcome to Java!
*********************************************
Two different class:
package hello.vijay.application;
public class oneclass {
public void display()
{
System.out.println( "Welcome to Java!" );
}
}
public class oneclass {
public void display()
{
System.out.println( "Welcome to Java!" );
}
}
package hello.vijay.application;
public class simpleclass
{
public static void main( String args[] )
{
oneclass one =new oneclass();
one.display();
}
}
public class simpleclass
{
public static void main( String args[] )
{
oneclass one =new oneclass();
one.display();
}
}
Running Procedure:
To compile both classes at once:
javac oneclass.java simpleclass.java
You can compile all the classes in the directory with the command:
javac *.java
And run the main class:
java simpleclass
The output is:
Welcome to Java!
Related Posts :
- Back to Home »
- Example program , Simple Program »
- Creating an object of class and calling its display method