what is the difference between data abstraction an
École, étude et sujet
CMSC132
CMSC132
Vendeur
S'abonner
Vendarsol
Avis reçus
Aperçu du contenu
CMSC132 Final Exam Fawzi With 100% Correct And Verified Answers What are the two types of abstraction?
Procedural and Data Abstraction
What is procedural abstraction?
Procedural abstraction is a type of abstraction in which the user is aware of what actions are being performed, but they are not told how the action is performed.
What is data abstraction?
Data abstraction is the concept in object-oriented programming that deals with hiding the complex implementation details of data structures and exposing only the necessary and relevant aspects to the user.
What is the difference between data abstraction and procedural abstraction?
Data abstraction deals with the nature and manipulation of data, hiding its complexities, while procedural abstraction focuses on the process or method of achieving a task, hiding the steps or algorithms involved. Both are used to simplify the design of software and enhance readability, maintainability, and reusability.
What is an abstract data type?
Abstract data type (ADT) is an entity that has values and operations. More formally, an abstract data type is an implementation of interfaces (a set of methods). Note that it is “abstract” because it does not provide any details surrounding how these various operations are implemented.
An abstract data type is a blueprint for the data structure. It defines the data and the operations that can be performed on the data, but it does not specify how these operations will be implemented.
An example of an abstract data type is a queue, which supports the operation of inserting items to the end of the queue as well as the operation of retrieving items from the front of the queue. Note, again, that we are not concerned with how these operations should be performed internally.
What is the difference between procedural abstraction and encapsulation
Procedural abstraction is when the user knows how to use a method, but not the exact method implementation, while encapsulation is hiding variables using private
Encapsulation: Think of the BankAccount as a secure vault. You have some controls (methods) to interact with what's inside (the data), but you can't directly access or see the contents (internal state).
Procedural Abstraction: Consider the process of depositing money as a black box. You put the money in (call the deposit method), and the system handles all the complex processes of updating your account balance. You don’t see or need to understand these internal workings. What is an interface?
An interface specifies a set of methods that another class must implement. They are polymorphic, and follow an is-a relationship.
As an example, consider an animal interface. If an elephant implements the animal interface, we can perform tasks that are meant for animals with elephants (such as passing an elephant into a function that accepts animals).
T/F A class can be used as a blueprint for another class.
True, a class can extend another class and implement functions from its super class in an is-
a relationship.
T/F Instantiating an interface will compile but throw an error.
False. If you instantiate an interface, your code will not compile.
T/F Missing an implementation for any method in an interface will compile but throw an error.
False. Your code won't even compile if you don't implement an interface method.
What is a default method?
A default method is a default implementation of a method in an interface. If a class implements an interface with a default method, it is not required to provide an implementation for that method , but can override if necessary.
How would you check that a method is-a -nother type or is a subclass of it in Java?
You would use instanceOf to verify that a class is an instance of another class.
if (p instanceof Animal) { /* Code to be executed */
}
T/F instanceOf is not a method
True. instanceOf is not a method, it is an operator, similar to "+," or "*"
What is a collection?
Collections are objects that group multiple elements into one unit.
What is the variable declaration that takes in any collection in Java?
Collection<Integer> elements;
Can be used like:
elements = new ArrayList<Integer>();
elements = new LinkedList<Integer>(); Name two of the built in functions in a Collection
.shuffle() and .sort()
What is this variable initialization called without a generic?
List myL = new ArrayList();
Raw type.
You can cast the elements in a raw type to another object without getting a runtime error. Java will permit us to add any type to the list.
So
B b = (B) myL.get(0);
Will compile without an error - unlike if we did pass in a type other than B.
T/F Iterable is a class.
False. It is an interface
How do you iterate over a collection in Java?
If a collection implements Iterable, we can use a combination of .iterator and .hasNext() to iterate over a
collection.
ArrayList<Integer> arr = new ArrayList<Integer>();
Iterable<Integer> arrIterator = arr.iterator();
while(arrIterator.hasNext()) {
System.out.println(arrIterator.next());
}
What is an automatic alternative to using an Iterator?
Using a forEach loop (enhanced for loop)
Using forEach(T object : objects) uses the iterator by default.
ArrayList<Integer> arr = new ArrayList<Integer>();
for(int arrValue : arr) {
System.out.println(arrValue));
}
What method does the Comparable interface implement?
Les avantages d'acheter des résumés chez Stuvia:
Qualité garantie par les avis des clients
Les clients de Stuvia ont évalués plus de 700 000 résumés. C'est comme ça que vous savez que vous achetez les meilleurs documents.
L’achat facile et rapide
Vous pouvez payer rapidement avec iDeal, carte de crédit ou Stuvia-crédit pour les résumés. Il n'y a pas d'adhésion nécessaire.
Focus sur l’essentiel
Vos camarades écrivent eux-mêmes les notes d’étude, c’est pourquoi les documents sont toujours fiables et à jour. Cela garantit que vous arrivez rapidement au coeur du matériel.
Foire aux questions
Qu'est-ce que j'obtiens en achetant ce document ?
Vous obtenez un PDF, disponible immédiatement après votre achat. Le document acheté est accessible à tout moment, n'importe où et indéfiniment via votre profil.
Garantie de remboursement : comment ça marche ?
Notre garantie de satisfaction garantit que vous trouverez toujours un document d'étude qui vous convient. Vous remplissez un formulaire et notre équipe du service client s'occupe du reste.
Auprès de qui est-ce que j'achète ce résumé ?
Stuvia est une place de marché. Alors, vous n'achetez donc pas ce document chez nous, mais auprès du vendeur Vendarsol. Stuvia facilite les paiements au vendeur.
Est-ce que j'aurai un abonnement?
Non, vous n'achetez ce résumé que pour €18,54. Vous n'êtes lié à rien après votre achat.