Presentation is loading. Please wait.

Presentation is loading. Please wait.

Package A package is a logical container that contains classes,interfaces sub packages. Package provide a unique name space to its members and provide.

Similar presentations


Presentation on theme: "Package A package is a logical container that contains classes,interfaces sub packages. Package provide a unique name space to its members and provide."— Presentation transcript:

1 Package A package is a logical container that contains classes,interfaces sub packages. Package provide a unique name space to its members and provide a mechanism to implement access specification. A unique name space represents that members of a package can be uniquely identifies i.e. name space solves the problems of name conflicting. First party: Technology provider Second Party: Programmer/Developer Third Party: programmer/ Developer outside the orgnisation.

2 In case of packages members of packages are uniquely identify because they are referred in association with their package name. Syntax of accessing a package members: package name. member name Steps: to define a class as part of a package. Package package name; MUST be the first statement. In the definition of class and interface. Note: to provide the physical separation of members a package class files of a package are saved in a folder of the same name as the package.

3 Solution to run the program:1) to run the program jump one directory up and execute the program. 2) classpath (cp) is an environment variable that is used by the class loader to identify the location of user defined classes. Default value of the classpath is the current folder. Classpath can be set permanently or can be specified where a class is compiled or executed. > java –cp.\.. Pkgname.classname

4 Import keywords It is used to import the classes of one package into another. Syntax: import pkgname.classname. or import pkgname.*;//for all classes Note: 1) once imported class is directly referred without any association of its package name. 2)class and constructor must be publically defined in its package in order to import in other packages. Focfully creation of folders: Javac –d. Classname.java

5 Access Modifier With in class Same pkg sub cls Same pkg non sub cls Diff pkg sub cls Diff pkg non sub cls privateyesNono defaultyes no protectedyes no Publicyes

6 Protected method overriding Note: protected data members of a class can only be referred in a package using the reference variables of those class that are defined in the package. For example: in case of display protected member of class “One” of package p1,reference variable of one can’t be used in package p2. Package p1; Package p2; Protected display(); Display(); class One class Two

7 Note: overriding does not applicable on protected method. Method overriding or run time polymorphism is applicable in case of public,non static non final method.


Download ppt "Package A package is a logical container that contains classes,interfaces sub packages. Package provide a unique name space to its members and provide."

Similar presentations


Ads by Google