Normal Font On The Cover Page: Instruction: Use The Attached Answer Sheet For Part-I and Part-IV Question
Normal Font On The Cover Page: Instruction: Use The Attached Answer Sheet For Part-I and Part-IV Question
Instruction: use the attached answer sheet for part-I and Part-IV question
Part I: Short answer question (2 pts each)
1. Briefly describe the following object oriented basic concepts data abstraction , data
encapsulation and data binding –give full mark at least two concept must be
explained
2. Explain what each term of “ public static void main(String args[])” method mean in
Java? 0.5mark for each explanation
3. Define Abstract Class in java and support your answer by example ( 1 pts for definition
& pts for example )
Part II: Find out the error in the following program and rewrite it again by correcting the
class A
{ private int x=4; class A
int z=10; { private int x=4;
static int y=10; int z=10;
A() static int y=10;
{ A()
return x+z; {
} return x+z; // 1 mark for Identification & correction
private void display () }
{ private void display ()
System.out.println(“sum=”+ sum+ “y=”+y); {
} System.out.println(“sum=”+ sum+ “y=”+y);
class B extends A{ }
int d=0; class B extends A{
} int d=0;
public static void main(String arg[]) }
{ B b1=new B(); public static void main(String arg[])
b1.x=5; { B b1=new B();
b1.z=10; b1.x=5;// 0.5mark
b1.display(); b1.z=10;
}} b1.display();//0.5 mark
}}
1|Page
#2. Find out the error and rewrite it again
2|Page
Part: III: Assume all programs are error free and Write the output of the
following program in the given box
#1. Write the output (3pts)
class Teststatic2 {
static int x=8; 1 Mark for each output
Teststatic2 () {
++x; 6
incr(x);}
static void incr(int x){System.out.println(x+7); } 16
static { int y=5;
10
System.out.println(++y);
}
public static void main(String args[])
{
Teststatic a=new Teststatic();
System.out.println(++x);
}}
#2. Write the output (3 pts)
class Area {
int x=5, y=6;
Area(){this(3);}
Area(int x) 0.5 mark for each output
{this(x,8);}
Area(int a, int z)
360
{x=a+3;y=z+4;
System.out.println(x*y*5); } } 540
class Tri extends Area{
54.0
Tri()
{super(6); 540
System.out.println(x*y*0.5);}
54.0
Tri(int z)
{super(z);} } 21
class Circle extends Tri{
public Circle() {System.out.println(x+y); }
public static void main(String args[])
{ Area a1=new Area();
Tri t2=new Tri();
Circle c1=new Circle(); } }
3|Page
#3. Write the output (3pts)
class Test {
int a,b;
public Test(){
send();
} 0.5 mark for each output
public Test(int z){
this(4,z);}
Test(int a, int x) { After first call value ob1.b: 12
this.a = a;
b=x;} After first call value ob2.b: 10
Test mtest(Test t) {
After first call value ob3.b: 9
t.a+=3;
t.b+=6; ob1.a , ob2.a and ob3.a. after second Call: 9 11 10
Test temp = new Test(a,b);
return temp; }
void send(){
mtest(this);}}
class TestObjasretuntype {
public static void main(String args[]) {
Test ob1 = new Test();
Test ob2= new Test(5,4);
Test ob3=new Test(3);
//ob1.send();
ob1= ob1.mtest(ob1);
ob2=ob2.mtest(ob2);
ob3=ob3.mtest(ob3);
System.out.println("After first call value ob1.b: " + ob1.b);
System.out.println("After first call value ob2.b: " + ob2.b);
System.out.println("After first call value ob3.b: " + ob3.b);
ob1=ob1.mtest(ob1);
ob2 = ob2.mtest(ob2);
ob3=ob3.mtest(ob3);
System.out.println("ob1.a , ob2.a and ob3.a. after second Call:" + ob1.a+" "+ob2.a+" "+ob3.a);
}}
4|Page
#4. Write the output (3 pts)
5|Page
Part IV: Program Writing (8%)
Assume ASTU students, students are categorized into extension and regular student, regular
students are categorized into undergraduate and graduate students, the behavior and state of all
classes listed in the table below
Class Behavior state
Extension student Registration, add and drop course , show studId,name, dept, semester
grade, make payment payment,
Regular student Registration ,add and drop course , view studId ,name, dept, dormitory
grade, no,blockno,café type
Undergraduate Registration ,add and drop course , view studId ,name, dept, dormitory
student grade, fill-CostSharing no, blockno , café type
,costsharing
Graduate student Registration ,add and drop course , view studId ,name, dept, thesis
grade, thesis payment, submit sponsor fund, specialization ,sponsor
1. Based on the class behavior and state in the above case ,Define all classes by
implementing the concepts of inheritance using java (4pts)
2. Implement either registration or Add&Drop course Behavior (2pts)
3. Identify the type of inheritance that can be implemented in the above case support your
answer by example (2pts)
Answer : #1 each class has 1 mark
class student{
String studId, name, dept
void Registration(String ID, String name, String dept)
{ #2 –
studId=ID; 2marks
this.name=name;
this.dept=dept;
}
void addDrop( )
{}
void view ()
{}}
6|Page
class extenstionStudent extends student
{
float payment;
void makepayment(float pay){
payment=pay;
}
}
class RegularStudent
{
int dormitory no,
String blockno,
Sting café type
}
class UnderGraduate extends RegularStudent
{
float costsharing;
void fillCostSharing(){}
}
class PostGraduate extends RegularStudent
{
Stiring Specialization ;
float thesis-fund;
String sponsor ;
void makepayment(){}
void sponsor (){}
}
#3 1 mark for each
A) Multiple : Student RegularStudent UnderGraduate
B) Hirarcical :
Student RegualrStudent
7|Page