[go: up one dir, main page]

0% found this document useful (0 votes)
15 views5 pages

MC 307 Assignment-2

The document is an assignment for an Object-Oriented Programming course, detailing various programming tasks and questions. It includes error identification and explanation for several Java code snippets, as well as questions about Java keywords, ArrayList advantages, and serialization of objects. Additionally, it requires the creation of classes with specific attributes and methods.

Uploaded by

Tausif Nawaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

MC 307 Assignment-2

The document is an assignment for an Object-Oriented Programming course, detailing various programming tasks and questions. It includes error identification and explanation for several Java code snippets, as well as questions about Java keywords, ArrayList advantages, and serialization of objects. Additionally, it requires the creation of classes with specific attributes and methods.

Uploaded by

Tausif Nawaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MC 307 OBJECT ORIENTED PROGRAMMING

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);
}
}

(b). abstract class shape


{
int a;
abstract int fun();
}
class rectangle extends shape
{
int b;
void print()
{
System.out.println(“Hello OK”);
}
}
class test
{
public static void main (String[ ] args)
{
rectangle obj = new rectangle();
obj.print();
}
}

(c). class shape


{
int a;
void sum()
{
System.out.println(“Hello”);
}
}

class rectangle extends shape


{
void print()
{
System.out.println(“OK”);
}

}
class testing
{
public static void main (String[ ] args)
{
shape obj = new rectangle();
obj.print();
obj.sum();
}
}

(d). class regular


{
int a;
void fun()
{
System.out.println(“True”);
}
}
public interface irregular
{
int b;
void fun()
{
System.out.println(“False”);
}

class test extends regular implements irregular


{
void fun()
{
System.out.println(“Both True and False”);
}

}
class testing
{
public static void main (String[ ] args)
{
test obj1 = new regular ();
obj1.fun();
}
}

(e). class test


{
public test( )
{
System.out.println(“Are you crazy ?”);
}
}

class testing extends test


{
public testing( )
{
System.out.println(“Hello No !!”);
}
}
class tested extends testing
{
public tested( )
{
System.out.println(“You look so.”);
}
}

class exam
{
public static void main (String[ ] args)
{
tested obj1 = new tested();
testing obj2 = new testing();
test obj3 = new test();
}
}

(f). class test


{
int a;
public test(int z)
{
a=z;
System.out.println(“Object Created of Base Class”);
}
}
class real extends test
{
public real()
{
super();
System.out.println(“Object Created of Derived Class”);
}
}

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.

You might also like