U03
all
In Java, ..... we can create objects that belong to an abstract class if all abstract methods are implemented in object declarations. We can not create objects that belong to an abstract class using standard syntax of object declaration. We use the interface keyword to declare an interface. All of the others.
a
In OOP, which of the following statements is correct in terms of cohesion? Each method should perform one specific task only. Classes in a program should not depend too much on each other. In a class, there should not be too many functions. Each function should contain as less code as possible
b
In a class, non static fields are called as ........, and static fileds are called as ....... Class variables, instance variables Instance variables, class variables public fields, protected fields Default fields, public fields None of the others
a
In a subclass, a calling to a constructor of superclass ....... must be the first line in a constructor of the subclass. can be let at somewhere in a constructor of the subclass. must be let at the first line of subclass declaration. can be presented with the syntax: SubClass (parameters): super(parameters) { ... }
inherit, extends
Object-oriented programming allows classes to ____ commonly used state and behavior from other classes. In Java, the ____ keyword is used to declare a subclass of another class. use, extends inherit, extends have, extend use, implements None of the others
fields, methods
Real-world objects share two characteristics: They all have state and behavior. Software objects are conceptually similar to real-world objects: they too consist of state and related behavior. A software object stores its state in _____ and exposes its behavior through ______. fields, methods methods, fields classes, objects None of the other choices
all
Select a correct statement about encapsulation implementation in OOP: All of the others Data of a class should be hidden from the outside. All behavior should be accessed only via methods. A method should have a boundary condition.
d
Select a correct statement about interfaces. An interface is a class that has method implementations with no data. An interface is a class that has at least one abstract method. An interface is an abstract class with no data. In its most common form, an interface is a group of related methods with empty bodies.
none
Select a correct statement. None of the others. An abstract class can not contain a concrete method. An interface can contain only one method implementation. An abstract class must contain abstract methods only. No data field can be declared in an abstract class.
a
Select an incorrect statement about inner classes: An inner class cannot be declared inside a method of the outer class. There are 2 types of nested class: Static Nested classes, Inner classes (non-static classes). Outer class must contain an instance of the inner class then accesses member of this instance.
c
Select correct statement about interfaces. An interface is a class that has a method having empty body. An interface is a class that has at least one abstract method. In its most common form, an interface is a group of related methods with empty bodies. An interface is an abstract class. None of the others
a
Suppose class X contains the following method: void doSomething(int a, float b) { ... } Which of the following methods may appear in class Y, which extends X? (Choose one.) public void doSomething(int a, float b) { ... } private void doSomething(int a, float b) { ... } public void doSomething(int a, float b) throws java.io.IOException { ... } private void doSomething(int a, float b) throws java.io.IOException { ... }
objA=objB;
Suppose that A, B, C are classes in which B is a subclass of A. Study the following declarations: A objA; B objB; C objC; Select a valid statement. objA=objB; objA=objC; objB=objC; objB=objA; objC=objA; objC=objB;
c
Suppose that the class A contains an inner class, named B. In a method of A, to access data of a B object, ...... The B object must be created in the main method of the program. No restriction is examined because B is a subclass of A. The B object must be referred by a reference declared in A. None of the others.
b
Suppose x and y are of type TrafficLightState, which is an enum. What is the best way to test whether x and y refer to the same constant? (Choose one.) if ( x.equals( y ) ) if (x == y) if ( x.toString().equals ( y.toString () ) ) if ( x.hashCode() == y.hashCode() )
Class
The protected modifier can not be applied to... Object-level variables Class-level variables Class A method of a class None of the others.
inheritance
The re-use code ability is a result of the ...... in OOP. inheritance encapsulation polymorphism aggregation
c
The term "instance variable" is another name for ____, and the term "class variable" is another name for _____. static field, non-static field public field, protected field non-static field, static field default field, public field None of the others.
all
We can ...... declare an object that belongs to an abstract class. declare an object that belongs to an interface. declare an object that belongs to a class then initialize it as an subclass object. All of the others.
d
What does the default modifier mean? It means as the private modifier. I can provide access to any class in the different packages which is a super class. It means as the protected modifier. It provides access to any class in the same package.
b
Which of the following may override a method whose signature is void xyz(float f)? private int xyz(float f) public void xyz(float f) private void xyz(float f) public int xyz(float f)
super()
Which of the following methods can be used to call a constructor of a father class from the sub-class? father() callSuper() super() callFather()
Low coupling
Which of the following options we try to achieve while designing object oriented software? Low cohesion Low coupling High coupling High coupling and low cohesion
b
Which of the following restrictions apply to anonymous inner classes? (Choose one) . They may only read and write final variables of the enclosing class. They must be defined inside a code block. They may only call final methods of the enclosing class. They may not call the enclosing class' synchronized methods.
a
Which of the following statements is correct about overloading methods? Overloading methods are implemented in the same class Overloading methods are implemented with different implementation Overloading methods are implemented in different classes None of the others
d
Which of the following statements is correct about overridding methods? An overriding method does not need to return exactly the same type as the method it overrides. An overriding method does not need to have the same signatures as the method it overrides. An overriding method can be less accessible than the method it overrides. Each parent class method may be overridden once at most in any one subclass.
a
Which of the following statements is correct? Outer class must contain an instance of the inner class before accessing members of the inner class. Inner class must contain an instance of the outer class before accessing members of the outer class. Inner class must be a static class Inner class must be a non-static class
none
Which of the following statements is not a reason for using nested classes? It is a way of logically grouping classes that are only used in one place. It increases encapsulation. Nested classes can lead to more readable and maintainable code. None of the others.
b
Which of the following statements is not a reason for using nested classes? It increases encapsulation. It supports a way for easily creating an object that is declared in an enclosing class declaration. Nested classes can lead to more readable and maintainable code. It is a way of logically grouping classes that are only used in one place.
b
Which of the following statements is not true in terms of overriding methods? A parent class method may be overridden once at most in each it's subclass. An overriding method (in sub-class) can throw any checked exception (or subclasses of those exceptions) that are not declared in the overridden method (in supper-class). An overriding method must return exactly the same type as the method it overrides. An overriding method must not be less accessible than the method it overrides.
d
Which statement is correct about protected modifier? It means as the private modifier. It means as the default modifier. The protected modifier can only provide accessing to the members of the class itself. Only variables and methods may be declared as protected members.
none
With respect to Java, select a correct statement about interfaces. An interface is a class that has a method having empty body. An interface is a class that has at least one abstract method. An interface is an abstract class. None of the others.
tight coupling
You are assigned a job that you need to buy a lock to replace the old one in your company. A lock-set includes 2 components: a lock and a key. Each key can only fit one lock. A key and a lock is an example of ... tight coupling loose coupling high cohesion low cohesion
c
.......... is applied in a class. .......... is applied in a class hierarchy. Method overriding, method overloading. Method expanding, method generalization. Method overloading, method overriding. Method generalization, method specification. None of the others
Fields, methods
A software object stores its state in ..... and exposes its behaviors through ...... Methods, fields Classes, objects Fields, methods None of the others
d
An abstract class ......... must contain at least one abstract method. must contain all abstract method. can not contain any data field. can contain all concrete methods.
Constants
An interface can contain ........ Method implementations. Inner classes. Constants. All of the other.
d
Consider the following class: class MyClass { void myFunction(){} int myFunction() {return 0;} } Select a correct statement about MyClass. MyClass has implemented overriding methods MyClass has implemented overloading methods MyClass has implemented inheritance MyClass has a compile error.
tight coupling
Consider the following piece of code: import javax.swing.JTextField; class Counter { int count=0; void increment() { count++; } void reset() { count=0; } JTextField txt= new JTextField(); void display() { // display the count txt.setText("Counter:" + count); } } The bove code is an example of ...... loose coupling high cohesion low cohesion tight coupling