Basic OO concepts in Java/C++ Flashcards Preview

Comp 2150 > Basic OO concepts in Java/C++ > Flashcards

Flashcards in Basic OO concepts in Java/C++ Deck (46):
1

For what languages are pointers implicit?

Java and Ruby

2

For what language are pointers handled explicitly?

C/C++

3

In Java what thing does the linkedList structure look like?

A image thumb
4

How do Ruby variables work?

A image thumb
5

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

int * ptr;

ptr = malloc(sizeof(int));

*ptr = 5;

6

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

int x = 5;

int * intptr = &x;

7

How does the -> operator work in C++

int value = myList->data;

How would you access myLists's print method?

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( )

8

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

How does it work?

 

A image thumb
9

In general how do pointer types work in most languages?

A image thumb
10

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

A image thumb
11

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

A image thumb
12

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

A image thumb
13

14

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

A image thumb
15

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

A image thumb
16

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

What is the specific code?

A image thumb
17

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

A image thumb
18

How do you use a class in Java?

A image thumb
19

What does the public setting in a class do?

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

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

A image thumb
21

How do you compile in general with g++?

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

g++ myfile.cpp

add -0

g++ myfile.cpp -o myprogram

22

What is a namespace and how is it used?

A image thumb
23

In C++ code a simle node class

A image thumb
24

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

A image thumb
25

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

A image thumb
26

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

A image thumb
27

Give an example of coding main in C++

A image thumb
28

What are extraction operators and how do they work?

A image thumb
29

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

A image thumb
30

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

A image thumb
31

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

A image thumb
32

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

A image thumb
33

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

Q image thumb

A image thumb
34

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

A image thumb
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

A image thumb
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

A image thumb
37

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

A image thumb
38

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

A image thumb
39

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

A image thumb
40

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

A image thumb
41

What is happening in the following code?

Q image thumb

A image thumb
42

How does Dynamic Class binding work with the ListItem?

A image thumb
43

What is polymorphism and what are the benefits?

A image thumb
44

How do signatures work with abstract classes and subclasses?

A image thumb
45

Why do abstract classes exist?

 

A image thumb
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)