.


Divya

Java package


Packages are nothing directory of our file system that exist our file system they contain set of class file

Example of java package

package AllBoy;
public class Student{
public static void main(String args[]){
System.out.println("Student are playing");
}
}

How to compile java package

Syntax for compile java package

javac -d directory javafilename

How to access package from another package.

  1. import package.*;
  2. import package.classname;
  3. fully qualified name.

Example

class Fruit{
final void run(){System.out.println("eating");}
}
class Apple extends Fruit{
void run(){System.out.println("it is very costly");}
public static void main(String args[]){
Apple a= new Apple();
a.run();
}
}

Output:Compile Time Error

Java final class

Syntax of Super final class

final class A
{
}
class B extends A
{
}

Example

final class Fruit{}
class Apple extends Fruit{
void run(){System.out.println("It is very costly");}
public static void main(String args[]){
Apple a= new Apple();
a.run();
}
}

Output:Compile Time Error



.