java programs on package.

in this tutorial we are cover about java package and java package base program. 
a package is a group of similar type of classes, interface and sub packages.
package in java can be categorize in two form, built in package and user define package.
their is many built in packages such as java, lang, awt, javax, swing, net, io, util, sql, etc

advantage of java package:
  1. java program is used to categorize the classes and interface so that they can be easily maintained.
  2. java program provide access protection.
  3. java package remove name collision.

Code:

 

package mypack;

 

import java.util.Scanner;

 

public class student

{

 

public String nm;

 

public int rno,m1,m2,m3;

 

public void get()

{

 

Scanner s=new Scanner(System.in);

 

System.out.print("Enter name:");

 

nm=s.next();

System.out.print("Enter roll no.:");

 

rno=s.nextInt();

 

System.out.print("Enter Marks1:");

 

m1=s.nextInt();

 

System.out.print("Enter Marks2:");

m2=s.nextInt();

 

System.out.print("Enter Marks3:");

 

m3=s.nextInt();

 

}

public void display()

 

{

 

System.out.println("Name:"+nm); System.out.println("Roll No.:"+rno); System.out.println("Marks1:"+m1); System.out.println("Marks2:"+m2); System.out.println("Marks3:"+m3);

 

}

}

 

 

 

import mypack.*;

 

class result extends student

{

 

float avg;

 

void calculate()

 

{

 

avg=(m1+m2+m3)/3;

System.out.println("Avg="+avg);

 

}

 

}

 

class pack1

{

 

public static void main(String[] args) { result k=new result();

 

k.get();

k.display();

 

k.calculate();

 

}

 

}

 

Output :-

package

Post a Comment

0 Comments