Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: How to call classes
|
Posted: Mar 28, 2003 5:45 PM
|
|
You can't call classes, you can only call methods.
You have a just few things to fix: - Most importantly, your opening curlies were in the wrong place. They should be on the next line, not the same line as the condition or declaration. - You need to instantiate instances (objects) of a class and use those. - Only one class in a file can be public. - You need to use the [java] tags when posting code (see Formatting Your Post box on the right when posting). - Your naming convention looks like C#, not Java; in Java, your method names start with a lowercase letter.
/**
* Incredible stuff-doing technology.
*/
public class Firstdary
{
public String dontHardlyDoNuttin()
{
return getClass().getName() + " didn't hardly do nuttin'.";
}
public static void main( String [] args )
{
Firstdary firstDairy = new Firstdary();
Secondary secondDairy = new Secondary();
Thirdary thirdDairy = new Thirdary();
String stuff = firstDairy.dontHardlyDoNuttin() + "\n" +
secondDairy.doStuff() + "\n" +
thirdDairy.doThings();
System.out.println( "Results of this incredible technology:\n" + stuff );
}
}
/**
* This is the class to use if you want to get stuff done.
*/
class Secondary
{
public String doStuff()
{
return getClass().getName() + " did some stuff!";
}
}
/**
* This is the class to use if you want to get things done.
*/
class Thirdary
{
public String doThings()
{
return getClass().getName() + " did some things!";
}
}
|
|