CS213 Quiz # 2
CS213 Quiz # 2
struct A{ struct B {
void (*ping)(); void (*wiff)();
void (*pong)(); void (*ping)();
}; void (*pong)();
};
struct A* new_A() {
struct A* a = (struct A*)malloc( sizeof(struct A) );
a->ping = A_ping;
a->pong = A_pong;
return a;
}
struct B* new_B() {
struct B* b = (struct B*)malloc( sizeof(struct B) );
b->ping = B_ping;
b->pong = A_pong;
b->wiff = B_wiff;
return b;
}
When main() executes, what would the program output be, and why?
Answer:
Question # 2 [50 Points]
class Animal {
void talk() {
System.out.println( "Animal talking!" );
}
}
void talk() {
System.out.println( "Meow!!" );
}
}
void talk() {
System.out.println( "Woof!!" );
}
}
class PolymorphismApp {
makeTalk( ginger );
makeTalk( tiger );
makeTalk( max );
}
}
Answer: