public class ParamTest
{
public static void main(String[] args)
{
/*
* Test 1: Methods can't modify numeric parameters
*/
System.out.println("Testing tripleValue:");
double percent = 10;
System.out.println("Before: percent=" + percent);
tripleValue(percent);
System.out.println("After: percent=" + percent); /*
* Test 2: Methods can change the state of object parameters
*/
System.out.println("\nTesting tripleSalary:");
Employee harry = new Employee("Harry", 50000);
System.out.println("Before: salary=" + harry.getSalary());
tripleSalary(harry);
System.out.println("After: salary=" + harry.getSalary()); /*
* Test 3: Methods can't attach new objects to object parameters
*/
System.out.println("\nTesting swap:");
Employee a = new Employee("Alice", 70000);
Employee b = new Employee("Bob", 60000);
System.out.println("Before: a=" + a.getName());
System.out.println("Before: b=" + b.getName());
swap(a, b);
System.out.println("After: a=" + a.getName());
System.out.println("After: b=" + b.getName());
} public static void tripleValue(double x) // doesn't work
{
x = 3 * x;我在dos下运行,提示:类ParamTest是公共的,应在名为ParmTest.java的文件中声明
我想问,程序的开头不是已经声明了吗,为什么还要声明?
{
public static void main(String[] args)
{
/*
* Test 1: Methods can't modify numeric parameters
*/
System.out.println("Testing tripleValue:");
double percent = 10;
System.out.println("Before: percent=" + percent);
tripleValue(percent);
System.out.println("After: percent=" + percent); /*
* Test 2: Methods can change the state of object parameters
*/
System.out.println("\nTesting tripleSalary:");
Employee harry = new Employee("Harry", 50000);
System.out.println("Before: salary=" + harry.getSalary());
tripleSalary(harry);
System.out.println("After: salary=" + harry.getSalary()); /*
* Test 3: Methods can't attach new objects to object parameters
*/
System.out.println("\nTesting swap:");
Employee a = new Employee("Alice", 70000);
Employee b = new Employee("Bob", 60000);
System.out.println("Before: a=" + a.getName());
System.out.println("Before: b=" + b.getName());
swap(a, b);
System.out.println("After: a=" + a.getName());
System.out.println("After: b=" + b.getName());
} public static void tripleValue(double x) // doesn't work
{
x = 3 * x;我在dos下运行,提示:类ParamTest是公共的,应在名为ParmTest.java的文件中声明
我想问,程序的开头不是已经声明了吗,为什么还要声明?
tripleValue(percent);
改为
System.out.println("Before: percent=" + percent);
ParamTest.tripleValue(percent);
首先这个方法是static的,所以LZ的调用方式是正确的LZ是在DOS窗口下调用的话,应该把代码贴全了,顺便把错误也贴出来,
使用JAVA 命令运行应该指定一些东西,比如你main方法中用到的Employee类