2010-06-21 3 views

답변

2
+0

내가하고 싶은 일은 스크립트에 클래스를 만들고 (스크립트 파일에서 자바 클래스처럼 사용하는 것입니다.) 이것이 내가 필요한 것입니다. 내 프로젝트에서 수업을 가져오고 싶지는 않지만 스크립트에서 수업을 만들어야합니다. 수행하는 방법 ??? –

+0

당신이 할 수있는 최선의 방법은 자바 스크립트 객체를 생성하고 invokable에 캐스팅 한 다음 거기에서 해보는 것입니다. 그러나 어떤 종류의 플러그인 시스템을하지 않는 한, 당신은 다소 OOP 규칙을 위반하고 있습니다. – TheLQ

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); 

} 
} 
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); 
    } 
}