NOTES + PRACTICE QUESTIONS FOR THEORY EXAM
OBJECT-ORIENTED PROGRAMMING CSE1100
CSE TU Delft - Lieke Sanders
→ Course is now called Introduction to Programming
→ Includes general notes + explained MC/open/programming questions for the theory exam
(so not the computer exam!)
Index
(Facts stolen from) MC and open questions 2
Primitive vs reference 2
Compilation vs runtime errors 2
Inheritance 2
Arrays 2
Array copies 3
Class design 3
Static 5
Quality 5
== operator 5
Logical operators 6
Switch case 6
Values and pointers 6
Parameter passing 7
Static vs dynamic types 7
Compilation 8
Polymorphism 8
Iteration or recursion 9
Threads 9
Deadlock 9
Cyclomatic complexity 10
Streams 10
Overriding vs overloading 10
Tests 11
Exception tests 12
Programming questions 14
Patterns 14
Control flow 15
Reverse String 16
Capitalize first letter 17
Inheritance 17
Reader 18
Writer 19
Full class 19
,(Facts stolen from) MC and open questions
Primitive vs reference
Primitive Reference
Can not be null Can be null
Store the actual values Store the addresses
int/double/boolean/char/short/float/long/byte object/String/array
Compilation vs runtime errors
Compilation error Runtime error
Will prevent the program from running Will prevent the program from executing
Syntax/semantics Exceptions noticed while running program
Like too many/missing { } + forgetting ; + Like division by 0 (ArithmeticException) +
using a value without declaration NullPointerException
Inheritance
- In Java all classes inherit from the Object class directly or
indirectly. The Object class is root of all classes.
- Multiple inheritance is not allowed in Java.
- A non-abstract child class must override an abstract
method inherited from its parent by defining a method with
the same signature.
- Child classes can override and overload methods defined
in their superclass(es).
- A non-abstract class can not contain abstract methods.
Arrays
- An array is an arrangement of consecutive memory
locations.
- Using an array can lead to an
ArrayIndexOutOfBoundsException.
- An array does not grow automatically when you add elements to it.
- If you pass an array as a parameter, the memory address of that array is copied
rather than the values that are stored in the array.
, Array copies
What will happen if we run the main method?
The program will print true
Class design
1
- There is a non-abstract class Vehicle.
- BMW is a carmaker brand.
- There is more than 1 carmaker brand.
- Every BMW is a Vehicle.
Which of the following design choices is most appropriate?
x You should create a class BMW that inherits from Vehicle.
✓ The Vehicle class should have an attribute indicating the brand.
x There should be a “1 to 1” relationship between Vehicle and BMW.
x There should be a “1 to n” relationship between Vehicle and BMW.
OBJECT-ORIENTED PROGRAMMING CSE1100
CSE TU Delft - Lieke Sanders
→ Course is now called Introduction to Programming
→ Includes general notes + explained MC/open/programming questions for the theory exam
(so not the computer exam!)
Index
(Facts stolen from) MC and open questions 2
Primitive vs reference 2
Compilation vs runtime errors 2
Inheritance 2
Arrays 2
Array copies 3
Class design 3
Static 5
Quality 5
== operator 5
Logical operators 6
Switch case 6
Values and pointers 6
Parameter passing 7
Static vs dynamic types 7
Compilation 8
Polymorphism 8
Iteration or recursion 9
Threads 9
Deadlock 9
Cyclomatic complexity 10
Streams 10
Overriding vs overloading 10
Tests 11
Exception tests 12
Programming questions 14
Patterns 14
Control flow 15
Reverse String 16
Capitalize first letter 17
Inheritance 17
Reader 18
Writer 19
Full class 19
,(Facts stolen from) MC and open questions
Primitive vs reference
Primitive Reference
Can not be null Can be null
Store the actual values Store the addresses
int/double/boolean/char/short/float/long/byte object/String/array
Compilation vs runtime errors
Compilation error Runtime error
Will prevent the program from running Will prevent the program from executing
Syntax/semantics Exceptions noticed while running program
Like too many/missing { } + forgetting ; + Like division by 0 (ArithmeticException) +
using a value without declaration NullPointerException
Inheritance
- In Java all classes inherit from the Object class directly or
indirectly. The Object class is root of all classes.
- Multiple inheritance is not allowed in Java.
- A non-abstract child class must override an abstract
method inherited from its parent by defining a method with
the same signature.
- Child classes can override and overload methods defined
in their superclass(es).
- A non-abstract class can not contain abstract methods.
Arrays
- An array is an arrangement of consecutive memory
locations.
- Using an array can lead to an
ArrayIndexOutOfBoundsException.
- An array does not grow automatically when you add elements to it.
- If you pass an array as a parameter, the memory address of that array is copied
rather than the values that are stored in the array.
, Array copies
What will happen if we run the main method?
The program will print true
Class design
1
- There is a non-abstract class Vehicle.
- BMW is a carmaker brand.
- There is more than 1 carmaker brand.
- Every BMW is a Vehicle.
Which of the following design choices is most appropriate?
x You should create a class BMW that inherits from Vehicle.
✓ The Vehicle class should have an attribute indicating the brand.
x There should be a “1 to 1” relationship between Vehicle and BMW.
x There should be a “1 to n” relationship between Vehicle and BMW.