package 문

명명된 구성 요소를 편리하게 패키지할 수 있게 하는 JScript 패키지를 만듭니다.

package pname {
   [[modifiers1] pmember1]
   ...
   [[modifiersN] pmemberN]
}

인수

  • pname
    필수적 요소로서, 만들고 있는 패키지의 이름입니다.

  • modifiers1, ..., modifiersN
    선택적 요소로서, pmember의 표시 유형 및 동작을 제어하는 한정자입니다.

  • pmember1, ..., pmemberN
    선택적 요소로서, 클래스, 인터페이스 또는 열거의 정의입니다.

설명

패키지 내부에서는 클래스, 인터페이스 및 열거만 사용할 수 있습니다. 패키지 멤버에 대한 액세스를 제어하기 위해 해당 패키지 멤버를 표시 한정자로 표시할 수 있습니다. 특히 internal 한정자는 멤버를 현재 패키지 내에서만 볼 수 있는 것으로 표시합니다.

패키지를 가져오면 패키지 멤버의 이름이 가져오기 범위에서 볼 수 있는 다른 선언과 같은 경우를 제외하고 이름을 사용하여 직접 패키지 멤버에 액세스할 수 있습니다. 같은 이름의 패키지 멤버가 있는 경우 해당 패키지 이름으로 멤버를 한정해야 합니다.

JScript에서는 중첩 패키지의 선언을 지원하지 않으므로 패키지 내에서 클래스, 인터페이스 및 열거 선언만 나타날 수 있습니다. 다른 패키지에 중첩되었음을 나타내는 '.' 문자가 패키지 이름에 포함될 수 있습니다. 예를 들어, Outer라는 패키지와 Outer.Inner라는 패키지는 서로 특별한 관계를 가질 필요가 없으며 모두 전역 범위의 패키지에 해당됩니다. 그러나 이 이름에 따르면 Outer.Inner를 Outer 내부에 중첩된 것으로 간주할 수 있습니다.

예제

다음 예제에서는 간단한 세 개의 패키지를 정의하고 해당 네임스페이스를 스크립트로 가져옵니다. 일반적으로 각 패키지는 패키지 내용의 유지 관리 및 배포를 위해 별도의 어셈블리에 위치합니다.

// Create a simple package containing a class with a single field (Hello).
package Deutschland {
   class Greeting {
      static var Hello : String = "Guten tag!";
   }
};
// Create another simple package containing two classes.
// The class Greeting has the field Hello.
// The class Units has the field distance.
package France {
   public class Greeting {
      static var Hello : String = "Bonjour!";
   }
   public class Units {
      static var distance : String = "meter";
   }
};
// Use another package for more specific information.
package France.Paris {
   public class Landmark {
      static var Tower : String = "Eiffel Tower";
   }
};

// Declare a local class that shadows the imported classes.
class Greeting {
   static var Hello : String = "Greetings!";
}

// Import the Deutschland, France, and France.Paris packages.
import Deutschland;
import France;
import France.Paris;

// Access the package members with fully qualified names.
print(Greeting.Hello);
print(France.Greeting.Hello);
print(Deutschland.Greeting.Hello);
print(France.Paris.Landmark.Tower);
// The Units class is not shadowed, so it can be accessed with or without a fully qualified name.
print(Units.distance);
print(France.Units.distance);

이 스크립트는 다음과 같이 출력됩니다.

Greetings!
Bonjour!
Guten tag!
Eiffel Tower
meter
meter

요구 사항

.NET 버전

참고 항목

참조

import 문

internal 한정자

기타 리소스

한정자