LAB EXAM SET B
Q1. A class called Author is designed as shown in the class diagram. It contains:
Three private instance variables: name (String),
email (String), and gender (char of either 'm' or 'f');
(.5 marks)
One constructor to initialize the name, email and
gender with the given values;
public Author (String name, String email, char
gender) {......}(.5 marks)
public getters/setters: getName(), getEmail(),
setEmail(), and getGender();
(There are no setters for name and gender, as these
attributes cannot be changed.) (1 marks)
A toString() method that returns "author-name
(gender) at email",
e.g., "Tan Ah Teck (m) at
ahTeck@somewhere.com". (.5 marks)
Write the Author class. Also write a test program called TestAuthor to test the constructor and public
methods.(1 marks)
Q2. Fill the blanks to get given output (.5 marks for each blank)
class person
{
private String name;
person(String name)
{
___________ = name;
}
void print()
{
System.out.println("name="+name);
}
}
class student extends person
{
int rollno;
B(int rollno1,String name)
{
__________
rollno1=rollno;
}
void show()
{
___________
System.out.println("rollno="+rollno);
}
}
class xyz3
{
public static void main(String args[])
{
student s1 = newstudent(10,"ram");
s1.show();
}}
Output:
name=ram
rollno=10
Lab exam setb_5_5_2015

Lab exam setb_5_5_2015

  • 1.
    LAB EXAM SETB Q1. A class called Author is designed as shown in the class diagram. It contains: Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'); (.5 marks) One constructor to initialize the name, email and gender with the given values; public Author (String name, String email, char gender) {......}(.5 marks) public getters/setters: getName(), getEmail(), setEmail(), and getGender(); (There are no setters for name and gender, as these attributes cannot be changed.) (1 marks) A toString() method that returns "author-name (gender) at email", e.g., "Tan Ah Teck (m) at ahTeck@somewhere.com". (.5 marks) Write the Author class. Also write a test program called TestAuthor to test the constructor and public methods.(1 marks) Q2. Fill the blanks to get given output (.5 marks for each blank) class person { private String name; person(String name) { ___________ = name; } void print() { System.out.println("name="+name); } } class student extends person { int rollno; B(int rollno1,String name) { __________ rollno1=rollno; } void show() { ___________ System.out.println("rollno="+rollno); } } class xyz3 { public static void main(String args[]) { student s1 = newstudent(10,"ram"); s1.show(); }} Output: name=ram rollno=10