MC 307 Assignment-2
MC 307 Assignment-2
ASSIGNMENT-2
2023-24 SESSION
Q.1. Find the error(s), if any, and explain the reason for the error(s) in the given programs. If
there is no error then write the output of the given programs. Assume that all the header files
have been incorporated in the programs wherever necessary.
(a). abstract class test
{
int a;
int b;
int fun()
{
return a*b;
}
}
public class real
{
public static void main (String[ ] args)
{
test obj = new test();
obj.a=10;
obj.b=20;
int z = obj.fun();
System.out.println(z);
}
}
}
class testing
{
public static void main (String[ ] args)
{
shape obj = new rectangle();
obj.print();
obj.sum();
}
}
}
class testing
{
public static void main (String[ ] args)
{
test obj1 = new regular ();
obj1.fun();
}
}
class exam
{
public static void main (String[ ] args)
{
tested obj1 = new tested();
testing obj2 = new testing();
test obj3 = new test();
}
}
class hello
{
public static void main (String[ ] args)
{
real obj = new real();
}
}
(g). class test
{
static int a=10;
static void test(int z)
{
a=z;
System.out.println(“Object Created of Base Class”);
fun();
}
void fun()
{
System.out.println(“Object Created of Derived Class”);
}
}
class hello
{
public static void main (String[ ] args)
{
test obj = new test();
obj.test();
obj.fun();
}
}
Q.2. Explain “Super” and “This” keywords in Java with the help of a Java program.
Q.3. Explain the advantages of ‘ArrayList’ over ‘Arrays’ in Java by discussing at least four
methods of ‘ArrayList’ class that are not present in arrays.
Q.4. Create two classes namely “Person” and “Student”. Person class contains three instance
variables: 1. ID(int type), 2. address (string type), and 3. a reference variable of the class
Student. Class Student contains one instance variable: marks(int type). Provide a constructor
function in both the classes to initialize the instance variables of their corresponding classes.
You need to serialize and deserialize the objects of the class Person. Create one object of class
Person in your main function, and then serialize and deserialize this object.