a. Create a class student in the above package with the following attributes:
Name, age, gender. Include appropriate constructor and a method for
displaying the details.
b. Import above package and access the member variables and function
contained in a package.
a. Create a class student in the above package with the following attributes: Name,
age, gender. Include appropriate constructor and a method for displaying the
details.
package bca;
public class Student
{
String name,gender;
int age;
public void read(String n,int a,String g)
{
name=n;
age=a;
gender=g;
}
public void display()
{
System.out.println("Student Name is="+name);
System.out.println("Student Age is="+age);
System.out.println("Student Gender is="+gender);
}
}
------------------------------------------------------------------------------------------------------------------
b. Import above package and access the member variables and function
contained in a package.
import bca.Student;
class Studentaccess extends Student
{
public static void main(String args[])
{
Studentaccess obj = new Studentaccess();
obj.read("abc",25,"male");
obj.display();
}
}
0 Comments