I am writing an administrator class that all other classes I am writing are meant to inherit from. In this case I want the classes to inherit a main method, and I am planning on implementing a factory as well. There are a few sysouts that I have to write that include various class names such as charcount, linecount and the such. For this I need to be able to get the current class name, since this method will be inherited by multiple classes. Is there a way to do this in java? You can find an example of the sysout I am looking to do below:
System.out.println("Usage: className <src>\n");
Thank you all in advance, any help is appreciated!
edit: Hey guys!
Very sorry I wasnt clear before, I'll show the entire code below and try to further explain my idea. So what I am doing is essentially making a main method that checks to see if a file exists, and if the file exists, it will try to execute a certain function (All this will be in the command line).I am practicing factory design patterns (something I've never done before). I will use the execute part of the main method to call on some factory (not yet made) to create objects of subclasses of administrator and return things like charcount in a file and linecount in a file. The above question refers to one part of this main method that will print the usage of the subclass. So for example, I will have charcount inherit from administrator because the process of checking the file and is in the main method of administrator, however when I print the usage message, I dont want it to print "Usage: Administrator ", but "Usage: charcount ". I hope that clears things up, and sorry again for how badly I explained it above, you can find what I have so far as code below:
public class Administrator
{
private static File srcFile = null;
private static String srcFilename = "<srcFilename>";
public static void main(String[] args) throws IOException
{
//check the command line
if(args.length != 1)
{
System.out.println("Usage: charcount <src>\n");
return;
}
// Check if arguments are valid, if the srcFile exists, and if can create the dstFile.
if (args[0] != null)
{
//check <src>
srcFilename = args[0];
System.out.println( ": srcFilename '" + srcFilename + "'");
srcFile = new File(srcFilename);
if(!srcFile.canRead())
{
System.out.println("charcount: cannot open srcFile '" + srcFilename + "'");
return;
}
}
else
{
System.out.println("charcount: [OK] srcFilename = '" + srcFilename + "'");
}
}
public static int execute() {return 0;}
}