Write a package program using inheritance

Write a package program using inheritance

Package Creation Program
Step-1: Ecllipse Process
right click on src - new - package
and write package creation Program
package sateesh;
import java.util.*;
class A
{
    String name,location,address;
    char gender;
}
public class Student extends A
{
String id;
float marks,fee;
public Student()
{
    Scanner s=new Scanner(System.in);
    System.out.println("Enter name :");
    name=s.next();
    System.out.println("Enter location :");
    location=s.next();
    System.out.println("Enter address :");
    address=s.next();
    System.out.println("Enter gender :");
    gender=s.next().charAt(0);
    System.out.println("Enter id :");
    id=s.next();
    System.out.println("Enter marks :");
    marks=s.nextFloat();
    System.out.println("Enter fee :");
    fee=s.nextFloat();
}
public void studentDetails()
{
    System.out.println("Name of the student is : "+name);
    System.out.println("location of the student is : "+location);
    System.out.println("Address of the student is : "+address);
    System.out.println("Gender of the student is : "+gender);
    System.out.println("Student id is : "+id);
    System.out.println("Marks of the student is : "+marks);
    System.out.println("Student Fee is : "+fee);
}
}
Note: Do not run the package Program

Package calling Program

import sateesh.Student;
class Demo
{
    public static void main(String args[])
    {
    Student s=new Student();
    s.studentDetails();
    }
}

Output:

Enter name : sateesh
Enter location : Hyd
Enter address : kukatpally
Enter gender : M
Enter id : 1224
Enter marks : 98
Enter fee : 1000

Name of the student is : sateesh
location of the student is : Hyd
Address of the student is : kukatpally
Gender of the student is : M
Student id is : 1224
Marks of the student is : 98.0
Student Fee is : 1000.0


Packages In Java



More Questions


157 . Write a package program using data abstraction
158 . Write a package program using inheritance
159 . write a package program using polymorphism
160 . write a inner package program using polymorphism
161 . Write a program to handled the Arithmetic Exception
162 . Write a program to handled the InputMismatch Exception
163 . Write a program to handled the ArrayIndexOutOfBoundsException
164 . Write a program to handled the StringIndexOutOfBoundsException
165 . Write a java program to know exception details using Exception class
166 . Write a java program to know above exception details using printStackTrace() Method
167 . Write a java program to know above exception details using getMessage Method