You are on page 1of 23

Question 1 

(1 point)

Complete the statement:

When you think of object-oriented manner, everything is an   , and every object is a member of a
.

Blank 1: 

Blank 2: 
Question 2 (1 point)

It refers to an instance of a class in which it has states and behaviors.

Object
 a
Class
 b
Method
 c
Variables
 d
Question 3 (1 point)

__ can be defined as a template/blueprint that describes the behavior/state that the object of its
type support.

Method
 a
Class
 b
Object
 c
Variables
 d
Question 4 (1 point)

Which of the following IS NOT part when creating a class?

Accessor Methods
 a
Object Instantiation
 b
Instance Variables
 c
Mutator Methods
 d
Question 5 (1 point)

It is a method in Java used to make or control changes in the variables.

Mutator Methods
 a
Abstract Methods
 b
Accessor Methods
 c
Constructor
 d
Question 6 (1 point)

public class Employee {

String empNumber, empName;

double ratePerHour;

int numOfHours;

void setName(String name) {

empName = name;

String getName() {

return empName;

Based on the given codes above, which of the following method is a(n) constructor?

setName
 a
getName
 b
Employee
 c
None of the above.
 d
Question 7 (1 point)
Which of the following DOES NOT describe a constructor in a Java class?

Constructor can also be used as a Mutator by providing parameters used to initialize


 a instance variables when invoked.
Java constructor is invoked at the time of object creation.
 b
Constructor in java is a special type of method that is used to initialize the object.
 c
Constructor can have a return statement to return values after invoking.
 d
Question 8 (1 point)

public class Employee {

public Employee() {

//constructor with no parameter

public Employee(String employee, double pay) {

//constructor with parameter/s

public void Employee(String employee, double pay) {

//constructor with parameter/s

Based on the given codes above, which of the following constructor declaration is wrong?

public Employee()
 a
public Employee(String employee, double pay)
 b
public void Employee(String employee, double pay)
 c
None. All are correct.
 d
Question 9 (1 point)

Variables inside a loop is a(n) ____.


Local
 a
Instance
 b
Class/Static
 c
None of the above.
 d
Question 10 (1 point)

It refers to a variable type wherein access modifiers cannot be used.

Local
 a
Instance
 b
Class/Static
 c
None of the above.
 d
Question 11 (1 point)

A type of variable which is rarely used other than being declared as constant.

Local
 a
Instance
 b
Class/Static
 c
None of the above.
 d
Question 12 (1 point)

Encapsulation is also called as?

Data Overloading
 a
Data Hiding
 b
Data Encapsulation
 c
Data Hidding
 d
Question 13 (1 point)

The encapsulation is achieved by combining which ones into a class?

Objects and Attributes


 a
Methods and Classes
 b
Methods and Variables
 c
Methods and Objects
 d
Question 14 (1 point)

Which of the following is declated as private when performing encapsulation?

Methods
 a
Variables
 b
Classes
 c
Objects
 d
Question 15 (1 point)
public class Test {
public void DisplayAge() {
     int age = 10;
     age += 5;
     System.out.println("Age: " +age);
}
public static void main(String args[]) {
       Test test = new Test();
       test.DisplayAge();
}
}
 
 
In the code above, what type of variable age is?
Parameter
 a
Instance Variable
 b
Local Variable
 c
Class Variable
 d
Question 16 (1 point)
public class Test {
private int age;
public Test(int setAge) {
     age = setAge;
}
public void DisplayAge() {
     age += 5;
     System.out.println("Age: " +age);
}
public static void main(String args[]) {
       Test test = new Test(10);
       test.DisplayAge();
}
}
 
In the above code, what type of variable age is?
Class Variable
 a
Local Variable
 b
Parameter
 c
Instance Variable
 d
Question 17 (1 point)
class Encapsulation {

private String name;

private String address;

public void setName(String name) {

this.name=name;

public void setAddress(String address) {

this.address=address;

In the above code, setAddress is ______ method.


Accessor
 a
Getter
 b
Mutator
 c
Constructor
 d
Question 18 (1 point)
package PackA;

public class ModifSample {


    private String message;
    
   void setMessage(String message) {
        this.message = message;
    }
    
    String getMessage() {
        return message;
    }
    
}
//////////////////////////////////////////////////////////////

package PackB;

import PackA.ModifSample;

public class TestModif {


    public static void main(String[] args) {
        ModifSample mod = new ModifSample();
        mod.setMessage("Hello!");
        
        System.out.print(mod.getMessage());
    }
}

What would be the output of the code above?

Hello!
 a
Error - both mutator and accessor of class ModifSample are only visible within PackA
 b and subclasses
Error - both mutator and accessor of class ModifSample are only visible within its
 c class
Error - both mutator and accessor of class ModifSample are only visible within PackA
 d
Question 19 (1 point)
class AreaOfCircle {

    private static final double PIE = 3.14;


    private double radius;
    
    public void setRadius(double radius, double PIE) {
        this.radius = radius;
        this.PIE = PIE;
    }
    
    public double getArea() {
        return (radius *  radius) * PIE;
    }
}

public class Encapsulation {


    public static void main(String[] args) {
        AreaOfCircle circle = new AreaOfCircle();
        circle.setRadius(45.5, 3.14);
        
        System.out.println("Area: " +circle.getArea());
    }
}

Determine the output of the given codes above, and choose the BEST answer.

Area: 2070.58
 a
Error: Private variables are only visible within a class.
 b
Error: Variables declared as final cannot be changed.
 c
Error: Class AreaOfCircle must have a valid access modifier.
 d
Question 20 (1 point)

Data hiding refers to what type of OOP concept?

Encapsulation
 a
Abstraction
 b
Polymorphism
 c
Inheritance
 d
Question 21 (1 point)
A way to discover which of the two classes is the   base class and which is the subclass is
________.

Look at the class size


 a
Try saying the two class names together
 b
Polymorphism
 c
Both a and b
 d
Question 22 (1 point)
Which of the following is not an advantage to using inheritance?
Similar classes can be made to behave consistently.
 a
One big superclass can be used instead of many little classes. Correct.
 b
Code that is shared between classes needs to be written only once.
 c
Enhancements to a base class will automatically be applied to derived classes.
 d
Question 23 (1 point)
A base class can also be called a ______.
Subclass
 a
Derived class
 b
Child class
 c
Superclass
 d
Question 24 (1 point)
Which of the following choices is the best example of a parent/child relationship?
a.Rose/Flower
 a
c.Dog/Poodle
 b
b.Present/Gift
 c
d.Sparrow/Bird
 d
Question 25 (1 point)
The java keyword that creates inheritance is ___.
inherits
 a
static
 b
extends
 c
enlarge
 d
Question 26 (1 point)
A class named Building has public, nonstatic method named getFloors(). If School is a child of  
class Building and modelHigh is an object of type     School, which of the following statement is
valid?
Building.getFloors();
 a
School.getFloors();
 b
modelHigh.getFloors();
 c
All of the statements are valid.
 d
Question 27 (1 point)
Which of the following statement is true?
A child class inherits from a parent class.
 a
A parent class inherits from a child class.
 b
Both of the preceding statements are true.
 c
Neither a nor b is true.
 d
Question 28 (1 point)
When a subclass method has the same name and argument types as a superclass method, the 
subclass method _____ the superclass method.
overloads
 a
child class
 b
overrides
 c
overcompensates
 d
Question 29 (1 point)
When you instantiates an object that is a member of a subclass, the _______ constructor executes
first.
child class
 a
parent class
 b
subclass
 c
extended class
 d
Question 30 (1 point)
If the only constructor in a superclass requires arguments, its subclass ___________.
Must contain a constructor that requires arguments.
 a
Must contain a constructor
 b
Must not contain a constructor
 c
Must not contain a constructor that requires arguments.
 d
Question 31 (1 point)
If a superclass constructor requires arguments, any constructor of its subclasses must call the 
superclass constructor _________.
Multiple times if multiple arguments are involved
 a
As the first statement
 b
At some point
 c
As the last statement
 d
Question 32 (1 point)
A child class Motorcycle extends a parent class Vehicle. Each class constructor requires one
String argument. The Motorcycle class constructor can  call the Vehicle class constructor with
the statement ____.
Vehicle("Honda");
 a
Motorcycle("Harley");
 b
super("Suzuki");
 c
None of the above
 d
Question 33 (1 point)
class Base {
    public static void show() {
       System.out.println("Base::show() called");
    }
}
  
class Derived extends Base {
    public static void show() {
       System.out.println("Derived::show() called");
    }
}
  
class Main {
    public static void main(String[] args) {
        Base.show();
    }
}
 
Output of following Java Program?
Base::show() called
 a
Derived::show() called
 b
Runtime Error
 c
Compile Error
 d
Question 34 (1 point)
If you create a data field or method that is _______, it can be used within its own class or in any
classes extended from that class.
public
 a
protected
 b
private
 c
Both a and b
 d
Question 35 (1 point)
You call a static method using ________.
The name of its class, a dot, and the method name.
 a
The name of its class’s, superclass, a dot, and the method name.
 b
The name of an object in the same class, a dot, and the method name.
 c
Either a or b
 d
Question 36 (1 point)
You use _____ method access specifier when you create methods for which you want to prevent 
overriding in extended classes.
public
 a
subclass
 b
protected
 c
final
 d
Question 37 (1 point)
class Base {
    public void show() {
       System.out.println("Base::show() called");
    }
}
  
class Derived extends Base {
    public void show() {
       System.out.println("Derived::show() called");
    }
}
  
public class Main {
    public static void main(String[] args) {
        Base b = new Derived();
        b.show();
    }
}
 
 
 
Derived::show() called
 a
Base::show() called
 b
Base::show() called Derived::show() called
 c
None of the above.
 d
Question 38 (1 point)
When a parent class contains a static method, child classes _______ override it.
seldom
 a
frequently
 b
cannot
 c
must
 d
Question 39 (1 point)
The keyword super always refers to the _______ of the class in which you use it.

child class
 a
subclass
 b
derived class
 c
parent class
 d
Question 40 (1 point)

Within a subclass, you cannot override _______ methods.

constructor
 a
public
 b
static
 c
private
 d
Question 41 (1 point)
Which among the following best describes polymorphism?

It is the ability for a message/data to be processed in more than one form


 a
It is the ability for undefined message/data to be processed in at least one way
 b
It is the ability for a message/data to be processed in only 1 form
 c
It is the ability for many messages/data to be processed in one way
 d
Question 42 (1 point)

If same message is passed to objects of several different classes and all of those can respond in a
different way, what is this feature called?

Inheritance
 a
Polymorphism
 b
Overloading
 c
Overriding
 d
Question 43 (1 point)
In Polymorphism, __________ means there are several methods present in a class having
thesame name but different types/order/number of parameters.

Method Clustering
 a
Method Overriding
 b
Method Overloading
 c
Method Calling
 d
Question 44 (1 point)

On the other hand, ____________ allows a subclass to define a specific implementation of an


existing method that has the same name and arguments.

Method Overriding
 a
Method Clustering
 b
Method Calling
 c
Method Overloading
 d
Question 45 (1 point)

True or False:

In Method Overriding, Java knows which method to invoke by checking the method signatures
during compile time.

 True

 False
Question 46 (1 point)

Tru or False:

In Method Overloading, Java knows what method to invoke depending on what object has been
instantiated.

 True

 False
Question 47 (1 point)
What polymorphism type is being implement on the following code segement:

class Employee {
    public double GrossPay(double rate, double hrs) {
        return (rate*hrs);
    }

    public double GrossPay(double rate, double hrs, double bonus) {


        return ((rate*hrs)+bonus);
    }

    public double GrossPay(double rate, double hrs, double bonus, double incentive) {
        return ((rate*hrs)+(bonus+incentive));
    }
}

public class Demo {


    public static void main(String[] args) {
        Employee emp = new Employee();
        
        System.out.println("Gross Pay: " +emp.GrossPay(75.50, 80.3, 1050.50, 500.70));
    }
}
Method Overriding
 a
Method Calling
 b
Method Clustering
 c
Method Overloading
 d
Question 48 (1 point)

What polymorphism type is being implement on the following code segement:

class Employee {
    public double GrossPay(double rate, double hrs) {
        return (rate*hrs);
    }
}
class Supervisor extends Employee {
    public double GrossPay(double rate, double hrs) {
        return ((rate*hrs)+3000.50);
    }
}
class Manager extends Employee {
    public double GrossPay(double rate, double hrs) {
        return ((rate*hrs)+(5000.50));
    }
}
Method Overloading
 a
Method Clustering
 b
Method Overriding
 c
Method Calling
 d
Question 49 (1 point)

What is the output of the following code fragment?

class Shape {
private String shape = "Circle";
private static final double pie=3.14;

static void Display() {


System.out.println("Shape: " +shape);
}

static double GetArea(double radius) {


Display();
return pie * (radius*radius);
}
}

class OtherShape extends Shape {


private String shape = "Square";

static void Display() {


System.out.println("Shape: " +shape);
}

static double GetArea(double s) {


Display();
return s*s;
}
}
public class Demo {
public static void main(String[] args) {
Shape os = new OtherShape();

System.out.println("Area: " +os.GetArea(5.5));


}
}
Error - object instantiation must be OtherShape os = new OtherShape();
 a
Shape: Circle Area: 94.985
 b
Shape: Square Area: 30.25
 c
Error - methods are static and cannot overridden.
 d
Question 50 (1 point)
Method Overloading is also known as _____.
Static Polymorphism
 a
Dynamic Polymorphism
 b
Runtime Polymorphism
 c
Both a and b.
 d
Question 51 (1 point)
What is an abstract class?
An abstract class is any parent class with more than one child class, hides data and can
 a only be access through concrete methods.
An abstract class is a class which has at least one abstract method which cannot be
 b instantiated
An abstract class is one without any child classes
 c
Is a “base-class”
 d
Question 52 (1 point)

What is an abstract method? 

Is a method which cannot be inherited by its subclass without using an @Override tag.
 a
Is a method in the child class that overrides a parent method.
 b
Is any method in an abstract class.
 c
A method from an abstract which needs a non-abstract class for it to be implemented.
 d
Question 53 (1 point)

Can an abstract class define both abstract methods and non-abstract methods? 

No – it must have one or the other.


 a
Yes – the child classes will inherit both.
 b
Yes – but the child classes do not inherit the abstract methods.
 c
No – it must have all abstract methods.
 d
Question 54 (1 point)
Which of the following abstraction concept achieves 100% abstraction? 
Implement class
 a
Interface class
 b
Extend class
 c
Abstract class
 d
Question 55 (1 point)
What is an interface? 
A class with at least one abstract methods.
 a
A super class with abstract method
 b
A collection of abstract methods and constants.
 c
A sub class with abstract method
 d
Question 56 (1 point)

Determine what is wrong with following code segement:

interface Shapes {

public final double pie=3.14;

void DisplayShape();
void SetShape(String shape);
double AreaOfCircle(double r);
double AreaOfRectangle(double l, double w);
double AreaOfSquare (double s);
}
class Area implements Shapes {

private String shape;


public void DisplayShape() {

System.out.println("Shape: " +shape);


}

public void SetShape(String shape) {


this.shape = shape;
}

public double AreaOfCircle(double r) {


return (pie * (r*r));
}
}
Nothing is wrong with the code.
 a
Interface classes use extends keyword to create subclasses.
 b
All methods defined abstract must always be redefined in the subclass.
 c
Interface classes should have interface keywords on their methods.
 d
Question 57 (1 point)

Determine what is wrong the following code fragments:

interface Shapes {
public final double pie=3.14;
private String shape;
double AreaOfCircle(double r);

public void DisplayShape() {


System.out.println("Shape: " +shape);
}

public void SetShape(String shape) {


this.shape = shape;
}
}

class Area implements Shapes {


public double AreaOfCircle(double r) {
return (pie * (r*r));
}

A class that implement interface must implement all the methods declared in the
 a interface.
Interface classes could only define abstract methods and constants.
 b
Nothing is wrong with the codes.
 c
Interface classes should always define variables as private for data hiding.
 d
Question 58 (1 point)

Fill in the missing codes based on the rule set by Abstraction:

   Shapes {

private String shape;

abstract double AreaOfCircle(double r);

public void DisplayShape() {


System.out.println("Shape: " +shape);
}

public void SetShape(String shape) {


this.shape = shape;
}
}

class Area    Shapes {

public final double pie=3.14;

double AreaOfCircle(double r) {
return (pie * (r*r));
}
}

Blank 1: 
Blank 2: 
Question 59 (1 point)

Determine what is wrong with following code fragments:

public class Employee {


abstract double GetSalary();

void display() {
System.out.println("Employee Mgt.");
}
}

class Manager extends Employee {

private double rate, hrs;

Manager(double rate, double hrs) {

this.rate=rate;
this.hrs=hrs;
}

double GetSalary() {
return rate*hrs;
}
}
Nothing is wrong with the codes.
 a
Abstract methods can only be declared within an abstract class.
 b
abstract double GetSalary(); should be implement first in the parent class.
 c
Abstract methods cannot be inherited by a subclass if the parent class is not declared
 d abstract.
Question 60 (1 point)

Assuming item #39 has error/s, what should a programmer do to correct it?

Replace public keyword in the class Employee declaration with abstract.


 a
Remove abstract keyword and provide implementation for the GetSalary() method in
 b the class Employee.
Declare GetSalary() method as static.
 c
Both a and b are correct.
 d

You might also like