Prelim Lab Exam
Prelim Lab Exam
Prelim Lab Exam
Question 1
Correct
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[])
Correct
{
public : class B
}
int data;
}
};
class C: public A
{
class D:public A::B{ };
};
a. Single level inheritance is used, with both enclosing and nested classes
Question 3
Correct
Find the order of execution of constructors in Java Inheritance in the following bellow -
class Animal{
public Animal(){
System.out.println("Base Constructor");
}
}
public Cat(){
System.out.println("Derived Constructor");
}
}
}
}
d. None
Question 4
Correct
class Person
{
private Person()
{
age = 24;
}
}
{
public static void main(String[] args)
{
Person p = new Person();
System.out.println(p.age);
}
}
a. Syntax Error
b. Compilation error
d. 24
Question 5
Correct
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
◄ PRELIM EXAM
Jump to...