Oracle 1z0-804 Exam Practice Questions (P. 5)
- Full Access (150 questions)
- Six months of Premium Access
- Access to one million comments
- Seamless ChatGPT Integration
- Ability to download PDF files
- Anki Flashcard files for revision
- No Captcha & No AdSense
- Advanced Exam Configuration
Question #21
Given:

Which three statements concerning the OO concepts "is-a" and "has-a" are true?

Which three statements concerning the OO concepts "is-a" and "has-a" are true?
- AFlimmer is-a Plinkable
- BFlommer has-a Tagget
- CFlommer is-a Glommer
- DTagget has-a String
- EFlommer is-a Plinkable
- FFlimmer is-a Flommer
- GTagget is-a Plinkable
Correct Answer:
ABE
A: Flimmer implements Plinkable.
Flimmer is-a plinkable.
D:The relationship modeled by composition is often referred to as the "has-a" relationship. HereTaggethasaString.
F: Flommer extends Flimmer -
So there is an "is-a relationship between Flommer and Flimmer .
Note: Thehas-a relationship has anencapsulation feature (like private or protected modifier used before each member field or method).
ABE
A: Flimmer implements Plinkable.
Flimmer is-a plinkable.
D:The relationship modeled by composition is often referred to as the "has-a" relationship. HereTaggethasaString.
F: Flommer extends Flimmer -
So there is an "is-a relationship between Flommer and Flimmer .
Note: Thehas-a relationship has anencapsulation feature (like private or protected modifier used before each member field or method).
send
light_mode
delete
Question #22
Which two compile?
- Ainterface Compilable { void compile(); }
- Binterface Compilable { final void compile(); }
- Cinterface Compilable { static void compile(); }
- Dinterface Compilable { abstract void compile(); }
- Einterface Compilable { protected abstract void compile (); }
Correct Answer:
AD
AD
send
light_mode
delete
Question #23
Which is a key aspect of composition?
- AUsing inheritance
- BMethod delegation
- CCreating abstract classes
- DImplementing the composite interface
Correct Answer:
B
In the composition approach, the subclass becomes the "front-end class," and the superclass becomes the "back-end class." With inheritance, a subclass automatically inherits an implemenation of any non-private superclass method that it doesn't override. With composition, by contrast, the front-end class must explicitly invoke a corresponding method in the back-end class from its own implementation of the method. This explicit call is sometimes called "forwarding" or
"delegating" the method invocation to the back-end object. Note: Composition means the same as:
* contains
* is part of
Note 2: As you progress in an object-oriented design, you will likely encounter objects in the problem domain that contain other objects. In this situation you will be drawn to modeling a similar arrangement in the design of your solution. In an object-oriented design of a Java program, the way in which you model objects that contain other objects is with composition, the act of composing a class out of references to other objects. With composition, references to the constituent objects become fields of the containing object. To use composition in Java, you use instance variables of one object to hold references to other objects.
B
In the composition approach, the subclass becomes the "front-end class," and the superclass becomes the "back-end class." With inheritance, a subclass automatically inherits an implemenation of any non-private superclass method that it doesn't override. With composition, by contrast, the front-end class must explicitly invoke a corresponding method in the back-end class from its own implementation of the method. This explicit call is sometimes called "forwarding" or
"delegating" the method invocation to the back-end object. Note: Composition means the same as:
* contains
* is part of
Note 2: As you progress in an object-oriented design, you will likely encounter objects in the problem domain that contain other objects. In this situation you will be drawn to modeling a similar arrangement in the design of your solution. In an object-oriented design of a Java program, the way in which you model objects that contain other objects is with composition, the act of composing a class out of references to other objects. With composition, references to the constituent objects become fields of the containing object. To use composition in Java, you use instance variables of one object to hold references to other objects.
send
light_mode
delete
Question #24
Given:

What two changes should you make to apply the DAO pattern to this class?

What two changes should you make to apply the DAO pattern to this class?
- AMake the Customer class abstract.
- BMake the customer class an interface.
- CMove the add, delete, find, and update methods into their own implementation class.
- DCreate an interface that defines the signatures of the add, delete, find, and update methods.
- EMake the add, delete, and find, and update methods private for encapsulation.
- FMake the getName and getID methods private for encapsulation.
Correct Answer:
CD
C:The methods related directly to the entity Customer is moved to a new class.
D: Example (here Customer is the main entity):
public class Customer {
private final String id;
private String contactName;
private String phone;
public void setId(String id) { this.id = id; }
public String getId() { return this.id; }
public void setContactName(String cn) { this.contactName = cn;} public String getContactName() { return this.contactName; } public void setPhone(String phone) { this.phone = phone; } public String getPhone()
{ return this.phone; }
}
public interface CustomerDAO {
public void addCustomer(Customer c) throws DataAccessException; public Customer getCustomer(String id) throws DataAccessException; public List getCustomers() throws DataAccessException; public void removeCustomer(String id) throws DataAccessException; public void modifyCustomer(Customer c) throws
DataAccessException; }
Note: DAO Design Pattern -
*Abstracts and encapsulates all access to a data source *Manages the connection to the data source to obtain and store data *Makes the code independent of the data sources and data vendors (e.g. plain-text, xml, LDAP,
MySQL, Oracle, DB2)
CD
C:The methods related directly to the entity Customer is moved to a new class.
D: Example (here Customer is the main entity):
public class Customer {
private final String id;
private String contactName;
private String phone;
public void setId(String id) { this.id = id; }
public String getId() { return this.id; }
public void setContactName(String cn) { this.contactName = cn;} public String getContactName() { return this.contactName; } public void setPhone(String phone) { this.phone = phone; } public String getPhone()
{ return this.phone; }
}
public interface CustomerDAO {
public void addCustomer(Customer c) throws DataAccessException; public Customer getCustomer(String id) throws DataAccessException; public List getCustomers() throws DataAccessException; public void removeCustomer(String id) throws DataAccessException; public void modifyCustomer(Customer c) throws
DataAccessException; }
Note: DAO Design Pattern -
*Abstracts and encapsulates all access to a data source *Manages the connection to the data source to obtain and store data *Makes the code independent of the data sources and data vendors (e.g. plain-text, xml, LDAP,
MySQL, Oracle, DB2)

send
light_mode
delete
Question #25
Which two are true about Singletons?
- AA Singleton must implement serializable.
- BA Singleton has only the default constructor.
- CA Singleton implements a factory method.
- DA Singleton improves a class's cohesion.
- ESingletons can be designed to be thread-safe.
Correct Answer:
CE
CE
send
light_mode
delete
All Pages