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

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?

23
Q

In C++ code a simle node class

24
Q

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

25
What are the C++ nodes and list methods code?
26
In general, how does main work in C++?
27
Give an example of coding main in C++
28
What are extraction operators and how do they work?
29
When using classes in C++, when do we need to use unqualified vs qualified names?
30
What is an example of and code fr a heap-based object in C++?
31
What is an example of and code for a stack-based object in C++?
32
In C++ stack vs heap based objects, why use one over the other?
33
What is the diagram for class hierachy for our general linkedlist example?
34
Using Java and our linkedlist example, what is the code for the Node class?
35
In general, what is a concrete class and what is an abstract class (in Java)
**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
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
37
Can a method be defined as abstract in a concrete class? Why?
38
In our ListItem example, what is the code for subclass for intAtom? (in Java)
39
In our ListItem example, what is the subclass Java code for Intchar?
40
In our ListItem example, what is the subclass code for GenericList?
41
What is happening in the following code?
42
How does Dynamic Class binding work with the ListItem?
43
What is polymorphism and what are the benefits?
44
How do signatures work with abstract classes and subclasses?
45
Why do abstract classes exist?
46
Why can't you use ( ) at the end of a stack based null constructor in C++?
putting ( ) will turn it into a forward reference(used in separate compilation)