脚本java:在脚本文件中创建一个类

时间:2010-06-21 15:53:33

标签: java scripting mozilla rhino jdk1.6

我想在脚本文件(javax.script)中创建一个java类。请帮忙

3 个答案:

答案 0 :(得分:2)

答案 1 :(得分:1)

import java.io.*;
public class Employee{
 String name;
 int age;
 String designation;
 double salary;

 public Employee (String name){
  this.name=name;
 } 
 public void empAge(int empAge){
  age=empAge;
 }
 public void empDesignation(String empDesig){
  designation=empDesig;
 }
 public void empSalary(double empSalary){
  salary=empSalary;
  }
 public void printEmployee(){
  System.out.println("Name:         "+name);
  System.out.println("Age:          "+age);
  System.out.println("Designation:  "+designation);
  System.out.println("Salary:       "+salary);

 }
}

答案 2 :(得分:1)

public class WesternTown {

     int stables;
     int saloon;
     int yearEstablished;
     int troublemaker;
     String sheriffsname;
     String location;


     public WesternTown() {
         stables=3;
         location="Wesrtern America";
         yearEstablished=1850;
     }

     public WesternTown(String name) {
         sheriffsname = name;
     } 


     public static void main (String [] args){

         WesternTown newtown = new WesternTown();
         WesternTown newname = new WesternTown("SHERIFFER");
         System.out.println("stables:      " + newtown.stables);
         System.out.println("saloon:       " + newtown.saloon );
         System.out.println("sheriffs:     " + newtown.sheriffsname ); 
         System.out.println("troublemaker: " + newtown.troublemaker );
         System.out.println("location:     " + newtown.location );
         System.out.println("yearEstablished: " + newtown.yearEstablished );
         System.out.println("The Name is:     " + newname.sheriffsname );
     }
}