Classes and Objects Flashcards
What is an Abstract Data Type (ADT)?
An ADT is a high-level data type that defines a set of values and a set of operations that can be performed on those values. It is an abstraction that hides the implementation details of a data structure, allowing users to work with the data in a more intuitive way.
What is encapsulation in the context of ADTs?
Encapsulation is the process of hiding the implementation details of an ADT from the user. This allows the user to work with the ADT at a high level, without having to worry about how it is implemented
How does an ADT consist of one or more classes?
An ADT can be implemented as a class or a group of classes that work together to provide the desired functionality. The classes define the data that is stored and the operations that can be performed on that data.
What are the parts of an ADT?
An ADT has two main parts: the data that is stored and the operations that can be performed on that data. The data is defined as a set of values, while the operations are defined as a set of functions or methods that can be called on those values.
What is the purpose of an ADT?
The purpose of an ADT is to provide a high-level interface for working with complex data structures. By encapsulating the details of the data structure, an ADT acts as a wall between the software component and the outside world, allowing users to work with the data in a more intuitive way.
How can an ADT be modelled in Java?
An ADT can be modelled in Java as an interface. The interface defines the methods that can be called on the data, but does not provide any implementation details.
What is the relationship between an ADT and a data structure?
An ADT is a high-level abstraction that defines the behavior of a data structure, while a data structure is a concrete implementation of that behavior. In other words, an ADT defines what operations can be performed on the data, while a data structure defines how those operations are implemented.
What is Object-Oriented Design (OOD)?
OOD is a programming paradigm that uses objects to model real-world entities and their relationships. It focuses on encapsulating data and behavior within objects and promoting code reusability through inheritance and polymorphism.
What is a class in OOD?
In OOD, a class is a blueprint for creating objects. It describes the attributes (data) that the object will contain and the methods (behavior) that the object will exhibit. A class can be thought of as a template for creating objects.
What are the parts of a class in OOD?
The two main parts of a class in OOD are attributes and methods. Attributes are the data that is stored by the class, while methods are the operations that can be performed on that data.
What is a data structure in OOD?
In OOD, a data structure is a way of organizing and storing data in a computer program. We can use one or more classes to construct a data structure.
What is an object in OOD?
An object is an instance of a class. It contains its own set of values for the attributes defined by the class, and can execute the methods defined by the class.
What is the difference between a class and an object in OOD?
A class is a blueprint or template for creating objects, while an object is an instance of a class. A class defines the attributes and methods that an object will have, while an object contains the specific values for those attributes and can execute the methods
What are some examples of data types that can be stored in a class in OOD?
Some examples of data types that can be stored in a class include integers (int), characters (char), strings (String), booleans (boolean), and floating point numbers (float or double).
What is the benefit of using OOD in software development?
: OOD promotes code reusability, which can save time and effort in software development. It also allows for better organization and management of complex programs, as well as easier maintenance and modification of existing code.
What are attributes in object-oriented programming?
Attributes are the data stored in an object. They describe the characteristics of an object and provide a way to store and retrieve data. Attributes are defined in a class and can be accessed by objects of that class.
What is the syntax for defining an attribute in Java?
In Java, attributes are defined using the following syntax:
access_modifier data_type attribute_name;
For example:
private String title;
What is the purpose of access modifiers in Java attributes?
Access modifiers in Java attributes control the visibility and accessibility of attributes. The four access modifiers in Java are private, protected, public, and default (also known as package-private).
What are behaviors in object-oriented programming?
Behaviors are the operations that can be performed on objects. They define what an object can do or how it can be manipulated. Behaviors are also defined in a class and can be called by objects of that class.
What is the syntax for defining a behavior in Java?
In Java, behaviors are defined using the following syntax:
access_modifier return_type method_name(parameter_list) { method_body }
For example:
public void play() { System.out.println(“Playing…”); }
What is the purpose of access modifiers in Java behaviors?
Access modifiers in Java behaviors control the visibility and accessibility of behaviors. The four access modifiers in Java are private, protected, public, and default (also known as package-private).
What is the difference between attributes and behaviors in object-oriented programming?
Attributes describe the data stored in an object, while behaviors describe the operations that can be performed on objects. Attributes are accessed using getter and setter methods, while behaviors are called directly by objects.
Can a behavior modify an attribute in an object?
Yes, a behavior can modify an attribute in an object. In fact, anything that modifies an attribute is considered a behavior. For example, a setter method is a behavior that modifies an attribute
What is a constructor in object-oriented programming?
A constructor is a special method that is used to create and initialize objects. It is called automatically when an object is created and is used to set the initial values of the object’s attributes.