package zeng;
import java.io.*;
// NO PUBLIC main here
public class Print {
public static void println(Object obj){
System.out.println(obj);
}
public static void println(){
System.out.println();
}
public static void print(Object obj){
System.out.println(obj);
}
public static void print(){
System.out.println();
}
//The new Java SE5 printf() (from C)
public static PrintStream printf(String format, Object... args){
return System.out.printf(format, args);
}
}
//-------------- eg 1 ---------------
package pkg;
import static zeng.Print.*;
// import static 语句一定要包含到类内的 static 方法,这样 static 方法是可见的,而 Print 类是不可见的,
//import zeng.Print;
public class p114 {
public static void main(String[] args) {
print("Avaliable from now on!");
// 这里如果多此一举使用 Print.会报错,因为不认识 Print 类,需要 import **.**.Print;
print(100);
print(100L);
print(3.1415926);
//test
//Print p=new Print();//The method print(String) is undefined for the type p114
//p.print("Can this be seen?,NO, It can't!");
//test 2
//Print.print("can this be seen?,yes too");//The method print(String) is undefined for the type p114
}
}
OUTPUT:
Avaliable from now on!
100
100
3.1415926
//-------------- eg 2 ---------------
package pkg;
import zeng.Print;
public class p114 {
public static void main(String[] args) {
/*
print("Avaliable from now on!");
print(100);
print(100L);
print(3.1415926);
*/
//The method print(String) is undefined for the type p114
//test
Print p=new Print();
p.print("Can this be seen?,yes you can");/*
The static method print(Object) from the type Print should be accessed in a static way */
//test 2
Print.print("can this be seen?,yes too");
}
}
OUTPUT:
Can this be seen?,yes you can
can this be seen?,yes too