100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CMSC132 Final Exam Fawzi With 100% Correct And Verified Answers $19.09   Add to cart

Exam (elaborations)

CMSC132 Final Exam Fawzi With 100% Correct And Verified Answers

 34 views  0 purchase
  • Course
  • CMSC132
  • Institution
  • CMSC132

CMSC132 Final Exam Fawzi With 100% Correct And Verified Answers

Preview 3 out of 17  pages

  • March 2, 2024
  • 17
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
  • what is data abstraction
  • what
  • CMSC132
  • CMSC132
avatar-seller
Vendarsol
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?

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller Vendarsol. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $19.09. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79223 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$19.09
  • (0)
  Add to cart