Prelim Lab Exam

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Home / My courses / UGRD-CS6203-2313T / PRELIM EXAM / Prelim Lab Exam

Started on Monday, 16 October 2023, 8:55 PM


State Finished
Completed on Monday, 16 October 2023, 9:14 PM
Time taken 19 mins 7 secs
Marks 50.00/50.00
Grade 100.00 out of 100.00


Question 1

Correct

Mark 10.00 out of 10.00

Check the program and find out if it will run properly?

class A

{
void msg()

{
System.out.println("Hello Java");

}
class B

{
void msg()

System.out.println("Welcome you");
}

}
class C extends A, B

{
public static void main(String args[])

C obj = new C();


obj.msg();//Now which msg() method would be called?

a. Got syntax error

b. Was able to run properly

c. Displayed the final output

d. Got compile time error 

Your answer is correct.


Question 2

Correct

Mark 10.00 out of 10.00

Which among the following is correct for the following code?


class A

{
public : class B

public : B(int i): data(i)


{

}
int data;

}
};

class C: public A

{
class D:public A::B{ };

};

a. Single level inheritance is used, with both enclosing and nested classes

b. Multi-level inheritance is used, with nested classes

c. Single level inheritance is used, with nested classes

d. Multi-level inheritance is used, with nested classes

Your answer is correct.


Question 3

Correct

Mark 10.00 out of 10.00

Find the order of execution of constructors in Java Inheritance in the following bellow -

class Animal{

public Animal(){
System.out.println("Base Constructor");

}
}

class Cat extends Animal{

public Cat(){
System.out.println("Derived Constructor");

}
}

public class Program {

public static void main(String[] args) {


Cat c = new Cat();

}
}

a. Derived to base class

b. Base to derived class


c. Random order

d. None

Your answer is correct.


Question 4

Correct

Mark 10.00 out of 10.00

What is the output of the following Java code?

class Person
{

private int age;

private Person()

{
age = 24;

}
}

public class Test

{
public static void main(String[] args)

{
Person p = new Person();

System.out.println(p.age);

}
}

a. Syntax Error

b. Compilation error

c. Run Time Error

d. 24

Your answer is correct.


Question 5

Correct

Mark 10.00 out of 10.00

Find the correct answer from the following two program -

a.
The private members can’t be accessed only in its own class

b. getter and setter methods of super class are not shown in the example 

c.
The private members can only be accessed using public

d. The derived class inherits all the members and methods

Your answer is correct.

◄ PRELIM EXAM
Jump to...

You might also like