Quiz3
The protected modifier can not be applied to...
Class
Object-level variables
Class-level variables
A method of a class
None of the others.
Which of the following statements is not a reason for using nested classes?
It supports a way for easily creating an object that is declared in an enclosing class declaration.
It increases encapsulation.
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.
Select a correct statement about interfaces.
In its most common form, an interface is a group of related methods with empty bodies.
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.
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.
……. Is applied in a class. ………. Is applied in a class hierarchy.
Method overloading, method overriding.
Method overriding, method overloading.
Method expanding, method generalization.
Method generalization, method specification.
None of the others
An abstract class ………
Can contain all concrete methods.
Must contain at least one abstract method.
Must contain all abstract method.
Can not contain any data field.
An interface can contain ……..
Constants.
Method implementations.
Inner classes.
All of the other.
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 referred by a reference declared in A.
The B object must be created in the main method of the program.
No restriction is examined because B is a subclass of A.
None of the others.
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 == y)
If ( x.equals( y ) )
If ( x.toString().equals ( y.toString () ) )
If ( x.hashCode() == y.hashCode() )
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 { … }
Which of the following restrictions apply to anonymous inner classes? (Choose one) .
They must be defined inside a code block.
They may only read and write final variables of the enclosing class.
They may only call final methods of the enclosing class.
They may not call the enclosing class’ synchronized methods.
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)
We can ......
All of the others.
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.
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) { … }
What does the default modifier mean?
It provides access to any class in the same package.
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.
Which statement is correct about protected modifier?
Only variables and methods may be declared as protected members.
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.
In Java, .....
We can create objects that belong to an abstract class if all abstract methods are implemented in object declarations.
All of the others.
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.
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
ObjC=objA;
ObjB=objA;
ObjC=objB;
The re-use code ability is a result of the …… in OOP.
Inheritance
Encapsulation
Polymorphism
Aggregation
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
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.
Inherit, extends
Use, extends
Have, extend
Use, implements
None of the others
The term "instance variable" is another name for ____, and the term "class variable" is another name for _____.
Non-static field, static field
Static field, non-static field
Public field, protected field
Default field, public field
None of the others.
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.
None of the others.
It increases encapsulation.
Nested classes can lead to more readable and maintainable code.
Select correct statement about interfaces.
In its most common form, an interface is a group of related methods with empty bodies.
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
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
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 ......
Tight coupling
Loose coupling
High cohesion
Low cohesion
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
Which of the following statements is not true in terms of overriding methods?
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).
A parent class method may be overridden once at most in each it’s subclass.
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.
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
Which of the following statements is correct about overridding methods?
Each parent class method may be overridden once at most in any one subclass.
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.
Which of the following options we try to achieve while designing object oriented software?
Low coupling
Low cohesion
High coupling
High coupling and low cohesion
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
A software object stores its state in ..… and exposes its behaviors through …...
Fields, methods
Methods, fields
Classes, objects
None of the others
In a class, non static fields are called as …….., and static fileds are called as …….
Instance variables, class variables
Class variables, instance variables
Public fields, protected fields
Default fields, public fields
None of the others
With respect to Java, select a correct statement about interfaces.
None of the others.
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.
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.
Consider the following class: class MyClass { void myFunction(){} int myFunction() {return 0;} } Select a correct statement about MyClass.
MyClass has a compile error.
MyClass has implemented overriding methods
MyClass has implemented overloading methods
MyClass has implemented inheritance
Which of the following methods can be used to call a constructor of a father class from the sub-class?
Super()
Father()
CallSuper()
CallFather()
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.
{"name":"Quiz3", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"The protected modifier can not be applied to..., Which of the following statements is not a reason for using nested classes?, Select a correct statement about interfaces.","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
More Quizzes
Math
1478
Global Financial system
8423
Recognizing and Defusing Agressive Behavior
1167
Understanding Human Development Quiz
18928
What is your spirit animal?
1050
How Well Do You Know Meh
1050
320
האם אתה *כבר* מולטי-טאלנט?
420
O quanto você conhece o livro Admirável Mundo Novo?
520
Hypothalamus
520
Which FNaF human are you?
11610
Personality type
100