-2

So I made a class that all it does is print(System.out.println("")) but when I make the method I have to have a parameter ie. public static void theprinter(String a){}.So I was wondering if there was a way to make the parameter not care what it was given instead it would give it to the System.out.println(); parameter no matter what it is given.

public class main {
    public static void main(String[] args) {
        printer PrinterWorkerObject = new printer();
        PrinterWorkerObject.theprinter("this is the only string i can print");
    }
}

public class printer {
    public static void theprinter(String a){
        System.out.println(a);
    }
}
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
Bondark
  • 35
  • 3

2 Answers2

3

Short Answer:

public class Printer 
{
    public static void print(final Object o)
    {
        System.out.println(o);
    }
}

Comments:

Learn the Java Style guide, ClassNames are UpperCamelCase, methodNames are lowerCamelCase for starters.

Methods should be single verbs, Classes should be single nouns.

  • yes I know the camel casing style, I just throw this together because I didn't want to put my entire project in the posting box. Thank you though. – Bondark Dec 05 '13 at 03:13
  • 1
    How much effort you put into your questions is how much effort others will put into their answers, sloppy questions aren't going to inspire as many people to help because they don't see the care or concern from you. So you kind of admit to being lazy, which is exactly what the sloppyness of this question conveys. –  Dec 05 '13 at 03:14
  • will it handle the primitive types ??? – Ahsan Shah Dec 05 '13 at 03:17
  • Well Jarrod, I am soooo sorry for wasting your time. Thank you for the help and the huge confidence boost! I hope to talk to you some other time. – Bondark Dec 05 '13 at 03:21
0

System.out.println(anyObject) it will print everythin.the toString() method of the object wil be called and resultant string wil be printed so dont care for any parameter passing to it

Deepak
  • 2,287
  • 1
  • 23
  • 30