Final Exam Flashcards

1
Q

Definition of a class…

A

A class is the template/blueprint from which individual objects are created; it describes the behaviors/states that object of its type support.

Collection of data members and methods

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

Definition of an object…

A

Objects have states and behaviors; they are an instance of a class.

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

Example of an object.

A

Dog:
states - color, name, breed
behaviors - wagging, barking, eating

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

Definition of a method…

A

Collection of statements that are grouped together to perform an operation.

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

What is a modifier…

A

Defines the access type of the method and it is optional to use.

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

What is the purpose of a constructor?

A

Initializes an object when it is created; create an instance of a class!

Can take only access modifiers – cannot be abstract, final, native, static, or synchronized.

Do not have a return type.

Have same name as their class name.

Uppercase.

Usually a noun.

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

When do you use a constructor?

A

To give initial values to the instance variables defined by the class, or to perform any other startup procedures required to create a fully formed object.

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

Does Java have a default constructor?

A

Java automatically provides a default constructor that initializes all member variables to zero.

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

What is an instance member?

A

Memory space is created each and every time whenever an object is created.

Meant for storing specific values.

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

What is a static member?

A

Memory space is created only once – when the class is loaded in the main memory; no objects are created.

Meant for storing common values.

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

What are the two types of data members?

A

Static

Instance (aka. non-static)

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

How is an instance data member accessed?

A

Object name.

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

How is a static data member accessed?

A

Class name.

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

What is the purpose of a method?

A

To execute code.

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

Give an example of a constructor for the class: Platypus

A

Platypus p1 = new Platypus();

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

Describe what a super class does…

A

Calls the overridden method of the superclass.

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

What class does Java extend when you do not explicitly extend a class?

A

Object class.

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

Why would we want to overload a constructor?

A

When we need more than one constructor which does different-2 tasks.

If you do not want to specify the initial capacity and capacity increment then you can simply use default constructor; example, Vector v = new Vector();

If you need to specify the capacity and increment then you call the parameterized constructor; example, Vector v = new Vector(10, 5);

19
Q

What is used for calling the default constructor from parameterized constructor?

A

this();

Should always be the first statement in the constructor body.

20
Q

What does a constructor allow you to do?

A

Create objects from a class.

21
Q

What is a primitive data type?

A

Predefined by the language and named by a keyword.

8 primitive types in Java: byte, short, int, long, float, double, boolean, char

22
Q

What is a reference data type?

A

Created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed; example: Animal animal = new Animal(“giraffe”);

23
Q

Where are instance variables declared?

A

In a class, but outside a method, constructor or any block.

24
Q

When are instance variables created?

A

When an object is created with the use of the keyword ‘new’ and destroyed when the object is destroyed.

25
Q

What is the purpose of an instance variable?

A

Instance variables hold values that must be referenced by more than one method, constructor or block, or essential parts of an object’s state that must be present throughout the class.

Instance variables can be declared in class level before or after use.

26
Q

What’s a string?

A

Sequence of characters.

27
Q

What does it mean when a class implements an interface?

A

The class inherits all the abstract methods of the interface.

Implicitly abstract and cannot have implementations.

Analogy: Class as signing a contract, agreeing to perform the specific behaviors of the interface.

28
Q

How is an interface declared?

A

Implements keyword.

Interfaces can extend other interfaces.

public interface NameOfInterface {
   //Any number of final, static fields
   //Any number of abstract method declarations\
}
29
Q

Describe each member of:

public static void main(String [] args)

A

public - modifier
static - can call method directly using class name and not creating an object of it
void - return type
main - method name
String[] args - string array of type args

30
Q

What is the purpose of the main method in Java?

A

Provides a start of application execution.

31
Q

What is a BST?

A

Ordered binary tree.

An abstract data structure where each node has a comparable key.

Smaller keys to the left of the parent.
Larger keys to the right of the parent.
Equivalent keys to the left or right – must keep consistency.

32
Q

Name the three types of BST removal types…

A

Key with no children.
Key with one child.
Key with two children.

33
Q

Explain the process to remove node with no children…

A

Remove the node.

34
Q

Explain the process to remove a node with one child…

A

Promote the child node to the node’s position that was removed.

35
Q

Explain the process to remove a node with two children…

A

Promote the right most node from the left subtree; largest value that is still less than the one you are replacing; the immediate predecessor in a sequence of values.

36
Q

What is a binary tree?

A

Tree where each node has up to two leaves.

37
Q

What is an adjacency list?

A

Collection of unordered lists used to represent a finite graph. Each list describes the set of neighbors of a vertex in the graph.

38
Q

What is an adjacency matrix?

A

Square matrix used to represent a finite graph. The elements of the matrix indicate whether pairs of vertices are adjacent or not in the graph.

39
Q

What does it mean to extend a class? How do you extend a class?

A

Extend by using the extends keyword.

Inheritance allows one class to “inherit” the properties of another class.

If you inherit from class A, then class B will also contain the same fields and methods.

40
Q

What is the syntax for an enhanced for loop?

A

for(declaration : expression) { }

declaration - of same type; value at each iteration
expression - the array you you need to iterate through

41
Q

What are the three access types and describe their scope…

A

Visible to the class only (private).

Visible to the world (public).

Visible to the package and all subclasses (protected).

42
Q

Provide an example of a user defined type…

A

If you have a class named Box; you can create an object of Box, or a user defined data type of Box.

Box b = new Box(); // Object
Box b = nb // User defined
43
Q

What is an AVL tree?

A

A self-balancing BST; the height of a node’s two child subtrees must not have a difference greater than one.

Searching for a value is faster than in a BST.

44
Q

What is an abstract class?

A

A Java abstract class can have instance methods that implements a default behavior.

Method that is declared, but contains no implementation