Basic OO concepts in Java/C++ Flashcards

1
Q

For what languages are pointers implicit?

A

Java and Ruby

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

For what language are pointers handled explicitly?

A

C/C++

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

In Java what thing does the linkedList structure look like?

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

How do Ruby variables work?

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

How do you declare a pointer, allocate memory and set the variable in C/C++?

A

int * ptr;

ptr = malloc(sizeof(int));

*ptr = 5;

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

How do you use a pointer in C/C++ of an existing variable.

A

int x = 5;

int * intptr = &x;

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

How does the -> operator work in C++

int value = myList->data;

How would you access myLists’s print method?

A

It dereferences myList, then get the “data” field.

It would be shorthand for (*myList).data, the brackets are required to ensure the dereferncing is done first.

myList->print( ) is equal to (*myList).print( )

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

How do you return the memory memory when you are done with an object in C++?

How does it work?

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

In general how do pointer types work in most languages?

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

How do you cast a pointer to another type and why is it a bad idea?

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

How do you define a class in Java? (what is the code)

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

How do you define a class in C++ (the code in one file)

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

What is a null constructor and how are they used in a class?

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

What does it mean for a constructor to be overloaded? How does this affect the null constructor?

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

What is the unique way constructors are used in C++ that can increase the speed of initialization?

What is the specific code?

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

What are the advantages of using door(numdoor) vs door = numdoor (objects as fields)

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

How do you use a class in Java?

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

What does the public setting in a class do?

A

A public class makes it visible from the outside world - it can have a main( ) method that will be invoked. However you can only have one public class.

20
Q

In java, how do you create a new object and how do you access the object fields or methods

A
21
Q

How do you compile in general with g++?

How do you compile and name the a.out file at the same time?

A

g++ myfile.cpp

add -0 <filename></filename>

g++ myfile.cpp -o myprogram

22
Q

What is a namespace and how is it used?

A
23
Q

In C++ code a simle node class

A
24
Q

In C++ what is the code for a simple list class?

A
25
Q

What are the C++ nodes and list methods code?

A
26
Q

In general, how does main work in C++?

A
27
Q

Give an example of coding main in C++

A
28
Q

What are extraction operators and how do they work?

A
29
Q

When using classes in C++, when do we need to use unqualified vs qualified names?

A
30
Q

What is an example of and code fr a heap-based object in C++?

A
31
Q

What is an example of and code for a stack-based object in C++?

A
32
Q

In C++ stack vs heap based objects, why use one over the other?

A
33
Q

What is the diagram for class hierachy for our general linkedlist example?

A
34
Q

Using Java and our linkedlist example, what is the code for the Node class?

A
35
Q

In general, what is a concrete class and what is an abstract class (in Java)

A

Concrete - fully implemented, meant to be instantiated

Abstract - providing elements to be inherited by subclasses, not meant to be instaniated itself

  • defined by adding the keyword abstract (abstract class ListItem{…)
  • even though you can never create an instance of an abstract class, we can define constructors
    • theses constructors are there to assist with inheritance
36
Q

using print( ) as an example, we have an abstract class: ListItem. How do you enforce the need for subclasses of ListItem to have a print method

A
37
Q

Can a method be defined as abstract in a concrete class? Why?

A
38
Q

In our ListItem example, what is the code for subclass for intAtom? (in Java)

A
39
Q

In our ListItem example, what is the subclass Java code for Intchar?

A
40
Q

In our ListItem example, what is the subclass code for GenericList?

A
41
Q

What is happening in the following code?

A
42
Q

How does Dynamic Class binding work with the ListItem?

A
43
Q

What is polymorphism and what are the benefits?

A
44
Q

How do signatures work with abstract classes and subclasses?

A
45
Q

Why do abstract classes exist?

A
46
Q

Why can’t you use ( ) at the end of a stack based null constructor in C++?

A

putting ( ) will turn it into a forward reference(used in separate compilation)