Objects & Classes Flashcards

1
Q

What is the main focus of procedural programming?

A

List of instructions to tell the computer what to do in a top down fashion

Procedural programming relies on procedures, routines, and sub-routines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the fundamental difference between an object and a class?

A

An object is a program component that knows how to perform certain actions, while a class is a definition of objects of the same kind.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the basic units of Object-Oriented Programming (OOP)?

A

Objects

Objects encapsulate both state (properties) and behavior (methods).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fill in the blank: In OOP, methods are part of an _______.

A

[object]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does a class encapsulate in OOP?

A

Static attributes (data) and dynamic behaviours (operations that operate on the data)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the benefits of Object-Oriented Programming?

A
  • Ease in software design
  • Ease in software maintenance
  • Reusable software
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is an instance in OOP?

A

A realization of a particular item of a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What keyword is used to define a class in Java?

A

class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a class library?

A

A collection of classes that can be used to create objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

True or False: Procedural languages are well-suited for creating reusable software components.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What do you call the method that sets up an object in Java?

A

Constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the primitive types in Java?

A
  • short
  • int
  • long
  • char
  • byte
  • double
  • float
  • boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the role of methods in an object?

A

They describe the behaviours of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the dot operator do in Java?

A

It is used to call (invoke) methods of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fill in the blank: A class is a _______ that defines the properties and behaviors common to a set of objects.

A

[blueprint]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the significance of encapsulation in classes?

A

It combines data structures and algorithms of a software entity inside the same box.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the three main components of a UML class diagram?

A
  • Class name
  • Variables
  • Methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What does the access control modifier determine in a class definition?

A

The visibility of the class and its members.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

True or False: Objects in programming are similar to real-world objects.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are reference types in Java?

A

Types that hold a reference to an object rather than an actual value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the purpose of a library management system in OOP?

A

To model real-world entities (books, users, checkouts) as objects with attributes and behaviors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the significance of methods like checkOut() and returnBook() in a Book class?

A

They define the behaviors associated with the Book object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Fill in the blank: A class can create multiple _______ of itself.

A

[instances]

24
Q

What is an example of a real-world entity modeled in OOP?

A

Books, Users, Checkouts in a library management system

25
How can objects interact in OOP?
By changing one another’s properties and causing events to happen.
26
What are the dynamic behaviors of a class called?
Methods
27
What is the purpose of using the 'new' operator in Java?
To create an object instance.
28
What does the method makeVisible() do in the context of a Circle object?
It displays the circle.
29
What is the purpose of class documentation?
To provide information necessary to create and utilize object instances of the class.
30
What is the purpose of class specifications?
To provide programmers with information necessary to create and utilize object instances of the class.
31
What does the method public Circle() do?
Creates a new Circle object at (x,y) coordinates (20,60) with an initial diameter of 30 pixels, colored blue and invisible.
32
What does the method public void makeVisible() do?
Makes the Circle visible. If it's already visible, it does nothing.
33
How far does the method public void moveRight() move the Circle?
Moves the Circle 20 pixels to the right.
34
What is the purpose of the method public void moveHorizontal(int distance)?
Moves the Circle a specified number of pixels horizontally; positive value moves right, negative value moves left.
35
What are the valid colors that can be set using the method public void changeColor(String color)?
* red * yellow * blue * green * magenta * black
36
What is the main function of the SettingSun class?
To create a sun that moves diagonally by using a loop to call movement methods.
37
What does the method public void changeSize(int newSize) do?
Changes the size of the Circle to the specified new size.
38
What is the significance of the String object type in Java?
String objects are widely used and can be created without the new operator.
39
What does it mean that String objects are immutable?
Once created, String objects cannot be changed; methods return new String objects instead.
40
What does the method String concat(String str) do?
Returns a new string consisting of the original string concatenated with the string parameter str.
41
What is the purpose of the ArrayList class in Java?
To provide a resizable array that can grow or shrink as needed.
42
What is the syntax to create an ArrayList that holds String objects?
ArrayList bookList = new ArrayList<>();
43
What method is used to add an element to an ArrayList?
add(element) method.
44
How do you access an element in an ArrayList?
Using the get(index) method.
45
What method would you use to find the number of elements in an ArrayList?
size() method.
46
What is the use of the Random class in Java?
To generate pseudorandom numbers.
47
What does the method nextInt(int bound) from the Random class do?
Generates a random integer between 0 (inclusive) and the specified bound (exclusive).
48
What is the purpose of the StringTokenizer class?
To separate a string into tokens based on delimiters.
49
What are the default delimiters in the StringTokenizer class?
* space * tab * new line
50
What does the method hasMoreTokens() return?
A boolean indicating if there are more tokens to process.
51
What is a class library?
A collection of classes that can be used when developing programs.
52
What does the import declaration do?
Allows the use of a class from a specified package in your program.
53
True or False: All classes of the java.lang package are imported automatically.
True.
54
Fill in the blank: The _______ class provides methods that generate pseudorandom numbers.
Random
55
What is the main advantage of using built-in classes in Java?
Saves time, reliability, performance, and readability.