- java program is used to categorize the classes and interface so that they can be easily maintained.
- java program provide access protection.
- 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 :-
0 Comments