Chapter 1: Overview Flashcards
What are the problems with procedural languages?
- When several functions need to access both global and local data which causes lots of programming errors
- Does not model real-world where functions carry out tasks and data stores information
What is a constructor?
A method called whenever a new object is created
What types of methods are private vs public?
Data fields are typically private while methods are public
What is inheritance?
The creation of one class derived or extended from a base class
Why might you use inheritance?
Makes it easy to add features to an existing class, makes it easy to reuse classes for a slightly different purpose (a key advantage of OOP)
What is polymorphism?
Polymorphism is treating objects of different classes the same way and allows different objects to implement the same method in different ways. For example, study() for the class economist() and data_scientist() both deriving from the base_class student() have different results
What is the biggest difference between C++ and Java?
Java has no pointers
What is the difference between value and object references in Java?
A value reference stores actual data (e.g. int intVal will store the value of intVal). An object reference stores the address of the object stored elsewhere in memory. “You can think of a reference as a pointer with the syntax of an ordinary variable”
Assignment: C++ vs Java
In C++, assignment copies the object, in Java, assignment copies the reference. The implication of course is that making updates to the object of reference will change any variables which refer to it
Equality: C++ vs Java
In C++ equality means the data in 2 objects is identical. In Java, equality means two references are equal.