IOOM Endsem 2022
IOOM Endsem 2022
1.
a. Draw some simple diagrams to illustrate what happens with each step of the following Java code 3
in memory: (CO1)
Person p = null;
Person p2 = new Person();
p = p2;
p2 = new Person();
p=null;
b. For Java code, when you pass an object as a parameter into a method, changes that are made to 3
the object persist after the method completes execution. However, if you pass in an int as a parameter
and change the value of that parameter in a method, the original int variable that was passed in remains
unchanged. Explain the behavior with an example and diagram. (CO1)
c. Create a class A in Java which will have two methods, viz, F1 and F2 having self declarative statements. 3
Within the first method F1, call the second method F2 twice: the first time without using this, and the
second time using this. Write main() function, create an object of class A and invoke F1. What will be
the program behavior? And why? (CO2)
d. Create a base class B in Java with only a non-default constructor, and a derived class D with both a 3
default (no-arg) and non-default constructor. In the derived-class constructors, call the base-class
constructor. Write main() function, create an object of class D. What will be the program behavior?
And why? (CO2)
2.
a. What is Reflection in Java? Assume class Test has one private integer data member ‘id’, and also 3
contains package access methods ‘set’ and ‘get’ for the data member and a default constructor. Write
code snippets to access these methods from outside of the class’s package. (CO1)
b. Write a Java code to read two strings (as command line argument). Write your own exception 3
“InputException” to validate input whether it is a valid string or not. If input is valid then output it, if not,
then throw InvalidInputException. Also define an exception called “NotMatchException” that is thrown
when two inputted strings are not equal. (CO2)
c. What do you think is the intention / requirement behind the provision of template in C++? Write a 3
template class declaration for ‘BinarySearch’. (CO2)
d. A Computer Science & Engineering department keeps track of its CSE students using some custom 4
software designed and developed by their own department using Java.
Each student is represented by a Student type object that features a pass_2() method that returns
true if and only if the student pass 10 department core (DC) courses during second year of their degree
course. With New Education Policy (NEP), BoS committee members of CSE department decided to give
Diploma certificate to those who want to exit the B. Tech and cleared 7 DC courses. Using inheritance
and polymorphism show how the software can continue to keep all Student type objects in one list in
code without having to change any classes other than Student class. (CO3)
Note: Use either C++ or Java to justify your answer. Don’t write logic for the method pass_2().
3.
a. Analyze the code and write the output of the following C++ code. Also explain the behavior. (CO2) 3
1. class A {
2. public:
3. A() { cout << "A's Constructor " << endl; }
4. A(const A& a) { cout << "A's Copy Constructor" << endl; }
5. virtual ~A() { cout << "A's Destructor" << endl; }
6. virtual void foo() { cout << "A's foo()" << endl; }
7. virtual A& operator=(const A& rhs) { cout << "A's op=" << endl;
}
8. };
9. class B : public A {
10.public:
11. B() { cout << "B's Constructor" << endl; }
12. virtual ~B() { cout << "B's Destructor" << endl; }
13. virtual void foo() { cout << "B's foo()" << endl; }
14.protected:
15. A mInstanceOfA; // don't forget about me!
16.};
17.
18.A foo(A& input) {
19. input.foo();
20. return input;
21.}
22.int main() {
23. cout << "Hello world!" << endl;
24. B myB;
25. B myOtherB;
26. A myA;
27. myOtherB = myB;
28. myA = foo(myOtherB);
29. return 0;
30.}
b. Give the output of following java code: (CO2) 3
public class Base{}
public class Derived extends Base{}
public class TestClass{
static void Test(Object x){
System.out.println(x.getClass());
System.out.println(x instanceof Base);
System.out.println(x. instanceof Derived);
System.out.println(Base.class.isInstance(x));
System.out.println(Derived. class.isInstance(x));
System.out.println(x.getClass() ==Derived.class);
System.out.println(x.getClass().equals(Base.class);
System.out.println(x.getClass().equals(Derived.class);
}
Public static void main(String[] args){
Test(new Base());
Test(new Derived());
}
}
c. A book is composed of a cover, a table of contents, and a number of pages, each of which can contain text 4
or diagrams. Draw a simple UML diagram to represent this information. (CO3)
--------------------------------------------------------------End------------------------------------------------------------