lab exam setb_5_5_2015

2
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 [email protected]". (.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() { ___________

Upload: daman-toor

Post on 07-Aug-2015

143 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Lab exam setb_5_5_2015

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 [email protected]". (.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 = new student(10,"ram");s1.show();}}

Output:name=ramrollno=10

Page 2: Lab exam setb_5_5_2015