0% found this document useful (0 votes)
6 views3 pages

MC 307 Assignment-3

The document is an assignment for an Object-Oriented Programming course, consisting of seven questions related to Java programming concepts. It covers topics such as memory allocation, output prediction of code snippets, constructor behavior, inheritance, polymorphism, and the Object class. Each question requires analysis and understanding of Java programming principles.

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)
6 views3 pages

MC 307 Assignment-3

The document is an assignment for an Object-Oriented Programming course, consisting of seven questions related to Java programming concepts. It covers topics such as memory allocation, output prediction of code snippets, constructor behavior, inheritance, polymorphism, and the Object class. Each question requires analysis and understanding of Java programming principles.

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/ 3

MC 307 OBJECT ORIENTED PROGRAMMING

ASSIGNMENT-3
2023-24 SESSION
Q.1 Given the following code:
class Test class ok
{ { public static void main(String[ ]
int b; args)
} {
class Hello Hello h = new Hello();
{ }
int a; }
Test t;
}

The variables a, t, and h reside in which part of memory (Say memory is divided in two parts:
heap and stack)

Q.2. Find the output of the following program:


class Test class ok
{ { public static void main(String[ ] args)
public Test() {
{ Test h = new Test();
System.out.println(“Hello”); Test p = new Test(100);
} p.Test(300);
public Test(int a) }
{ }
System.out.println(“Bye”);
}
public void Test(int b)
{
System.out.println(“Great”);
}
}
Q.3. Find the output of the following program:
class Test class ok
{ { public static void main(String[ ] args)
public Test() {
{ Test p = new Test(100);
this(100); Test h = new Test();
}
System.out.println(“Working”); }
}
public Test(int a)
{
super();
System.out.println(“Worked”);
}
}

Q.4. Consider the following statements:


S1: Constructors in a class can be made private.
S2: Static Instance Variables cannot be accessed by the class name.
S3: In inheritance hierarchy, we cannot override Final Methods of a class.
S4: Abstract classes do not have constructors.
Identify the incorrect statements.

Q.5. Consider the following statements:


S1: “Super” and “This”, both cannot be present together within a constructor.
S2: We can create objects of an Interface in Java.
S3: In polymorphism, derived class reference variable can refer to its base class object.
S4: Static methods of a class can be accessed by the class name.
Identify the correct statements.
Q.6. Find the output of the following program:
class Test class Hello extends Test
{ {
public Test() public static void main(String[ ] args)
{ {
System.out.println(“Hello”); Test h = new Test(); // Line 1
} Test v = new Test(); // Line 2
} Test z = new Test(); //Line 3
v= new Test();
h=v;
v=z;
//Remaining code
}
}
Let the objects created in Line 1, 2 and 3 be represented by “X”, “Y”, and “Z”. Which of the
following objects are eligible for garbage collection during the program execution ?

Q.7. Consider the following statements regarding the “Object” class (the parent class of all
classes):
S1: Object Class is an Abstract class, hence, objects of “Object” class cannot be created.
S2: All the methods in Object class are declared as final, hence, all of them cannot be
overridden.
S3: Reference variables of Object class can be created if required.
Which of the above statements are correct ?

You might also like