oop Flashcards

1
Q

Static vs nonstatic

A

Static functions belong to the class but not an object of the class, whereas nonstatic functions belong to an object of the class.

Non-static functions must be operated on an instantiated object of the class, static functions do not have to be on an instantiated object.

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

Hard coding vs soft coding

A

Hard coding - programmer codes the data

Soft coding - the data collection system codes the data without the programmer

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

Binary infix operators

A

+,-,/,*

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

-15/4 in java

A

This is equal to -3!

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

Java associativity?

A

left to right!

16/4/2 is 2 not 8

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

What does parseInt or parseDouble do?

A

Converts an string into the Int or Double that it means.

“9” turns into either 9 or 9.0

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

escape sequence

A

\

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

1 - 0.1 - 0.1 - 0.1 ?

A

.70000000001

This is due to the way the bits are stored in doubles/floats.

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

Relational operator meaning

A

1) == - equal
2) != - not equal
3) < - less than
4) > - greater than
5) <= - less than or equal
6) >= - greater than or equal

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

if statement inside an if statement

A

nested if!

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

What does the new keyword do?

A

allocates memory at RUNTIME

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

What is an object?

A

an abstract data type with state (data) and behavior (code). INSTANCE OF A CLASS.

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

Encapsulation

A

An object hides behavior and information from unauthorized users from directly accessing them

…. encapsulation is the BINDING of data, in OOP this refers to how objects store multiple kinds of data

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

communication from a sender object to a receiver objectvia a link is called a stimulus, andcommunication from a sender class to a receiver class via anassociation is called a message. A stimulus isan instance of a message much the way an object is an instance of aclass and a link is an instance of an association.

A

True

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

Abstraction

A

Capture only those details about an object that are relevant to current perspective. Abstraction is a way to deal with complexity, and hides this complexity from the user.

Allows for ease of development, as you just need to know how to use inputs to receive outputs. “Targetting relevant details for the user”

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

Inheritance

A

Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.

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

How to use inheritance? Purpose of inheritance?

A

‘extends’ keyword… re-usability of code

USE THIS FOR ABSTRACT CLASSES

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

Generalization?

A

A generalization is a form of abstraction whereby common properties of specific instances are formulated as general concepts or claims.

Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass.

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

If x inherits from b. What is their relationship?

A

x is a b

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

Subtyping

A

implemented or abstracted class is a ‘subtype’

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

Specialization

A

specialization means creating new subclasses from an existing class.

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

Overriding

A

over-riding or re-writing/changing default behavior of the base class

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

derived class/base class

A
derived = sub class
base class= super class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Can you instantiate an abstract class? Why or why not?

A

Abstract classes cannot be instantiated, but they can be subclasses using the ‘extends’ keyword.

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

A class with abstract methods is an abstract class

A

TRUE. If a class has abstract methods (that must be defined in a subclass, then it is an abstract class)

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

Concrete class

A

Derived class/subclass of an abstract class! This CAN be instantiated.

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

Multiple inheritance? How to do this?

A

THIS IS NOT ALLOWED IN JAVA. Any sub-class may only have ONE parent class.

But yeah multiple inheritance is a class being EXTENDED/inherited from multiple parent classes.

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

Diamond problem

A

if intermediate classes extend from a super class, then a 3rd level class extends from both intermediate classes (creating a diamond shape).

Doesn’t occur in java because java doesn’t support multiple inheritance.

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

Simple Association

A

semantically weak relationship (a semantic dependency) between otherwise unrelated objects.

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

Aggregation

A

Form of “association” that is an example of a ‘whole/part or parent/child’ relationship. Both the whole or part may exist without the other!

Death is independent.

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

Composition

A

Form of aggregation that is also part of the ‘wholle/part or parent/chid’ relationship. But if the parent object is destroyed, the child is as well.

The parent is composed of the child… child’s Death is dependent on parent.

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

Two kinds of asssociation

A
  • Class association (inheritance)

- Object association (simple association/composition/aggregation)

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

Association

A

interaction between objects… split into simple association/composition/aggregation

34
Q

Polymorhism

A
The ability of one object  to have different forms.
Most common in OOP is for a parent class reference is used to refer to a child class object.
35
Q

All objects share what in common?

A

All objects extend the object class in java

36
Q

Are all objects polymorphic?

A

Yes. Because they are instance’s of at least 2 parent classes… object and something else!

37
Q

How to test for polymorphism?

A

If an object is an ‘instanceof’ 2 or more classes!

This is also known as an ‘is-a’ test, telling you that the child is a parent/ it extends a parent.

38
Q

User defined types

A

These are types that are defined by the user, such as interfaces or classes.

39
Q

. vs ->

A

use ‘.’ to access field of this object or a method by name/reference

use ‘->’ to access field/method by pointer!

40
Q

Public access specifier

A

A class, method, constructor, interface, etc. declared public can be accessed from any other class in Java… as long as this public class is in the package or is imported!

41
Q

scope resolution operator

A

Declaring a method inside a class, then defining outside.

JAVA doesn’t have this, C++ uses ‘:’.

42
Q

Constructor

A

used to initialize the objects of class. Different kinds of constructors such as copy constructor, default constructor, etc…

43
Q

Default constructor

A

does not have parameters!

44
Q

Overloading and use with creating objects?

A

Overloading is defining the same method multiple times so that you can call them with different argument lists. This is used with constructor overloading, which allows you to have multiple constructors with different amounts of parameters/types of parameters to create an object of the same class.

45
Q

Copy constructor

A

creates an object by initializing it with an object of the same class, which has been created previously

46
Q

Does java create a default copy constructor?

A
Nope! You must create your own.
You do this by simply doing 
Constructor(Classname x){
//copy fields of x into a new object here
}
47
Q

Shallow vs deep copy

A

Shallow copy copies fields of old into new object

Deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields.

48
Q

Destructor

A

frees memory that was allocated dynamically on the heap at runtime

49
Q

accessor function

A

‘get’ functions… also know as getters. These access data members defined as private.

50
Q

‘this’

A

‘this’ is a reference to the current object. It is helpful especially when dealing with the fields of an object

51
Q

Const keyword in c++

A
  • variable/pointer that can’t be changed

- function arguements cannot be changed by body of function if this occurs

52
Q

Class variable vs instance variable

A
Class variable - variable that is shared among all instances of a class, and if changed, will change that variable of all instances of that class
Instance variable - variable that is specific to an instance of a class
53
Q

How are class variables declared?

A

Using static keyword.
public static int x = 10;

To use instance variable
public int x = 10;

54
Q

Can a private static member can be accessed outside the class except for initialization?

A

Nope! Only during initialization or using an instance of that class can you change a private static member.

55
Q

How are variables automatically initalized in java?

A
Uninitialized variables are automatically initialized to zero but 
if the variable is an instance variable and a class variable then if we don't initialize the instance variable the system by default initialize them to their respective default values.
56
Q

Friend functions

A

The functions which are not member functions of the class yet they can access all private members of the class are called friend functions.

57
Q

Operator overloading

A

Able to define 2 or more operators by overloading them!

58
Q

Is java platform independent?

A

Yes! It can be run on any java-supported machine as the JVM (java virtual machine) will convert into bytecodes based on the native machine.

59
Q

What is important for the Java source file names, in relation to class names?

A

The source file name must match the public class name in the program

60
Q

specific vs wildcard import

A

Specific import and wildcard import. Specific imports single classes, while wildcard imports all classes in a package

61
Q

What are the three categories of errors?

A

Syntax errors, runtime errors, and logic errors

62
Q

Java API

A

contains predefined classes and interfaces for developing Java programs

Such as object class n stuff

63
Q

Java JDK

A

(Java development kit) consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line

64
Q

Identifier

A

Identifiers are names for naming elements such as variables, constants, methods, classes, packages in a program

65
Q

How to declare a constant?

A

public final int

66
Q

To to cast

67
Q

2%1

68
Q

-24 % -5

69
Q

4 + 20 / (3 - 1) * 2 in Java

70
Q

Benefits of using Design Patterns

A
  1. Design Patterns are already defined and provides industry standard approach to solve a recurring problem, so it saves time if we sensibly use the design pattern. 2. Using design patterns promotes reusability that leads to more robust and highly maintainable code. It helps in reducing total cost of ownership (TCO) of the software product. 3. Since design patterns are already defined, it makes our code easy to understand and debug. It leads to faster development and new members of team understand it easily.
71
Q

How to write and/or/not in java

A

&& means AND
|| means OR
! means NOT

72
Q

What is a switch statement?

A
switch (x) {
    case 1: //if x ==1, do this
    ssystem.out.....
    break;
    case 2:
    break
73
Q

What happens in you include don’t break statement into a switch case?

A

Then it will continue to the next case instead of breaking out of the switch statement.

74
Q

Suppose x=10 and y=10 what is x after evaluating the expression (y > 10) && (x++ > 10).

A. 9
B. 10
C. 11

A

B. 10

Explanation: For the && operator, the right operand is not evaluated, if the left operand is evaluated as false.

75
Q

Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x++ > 10).

A. 9
B. 10
C. 11

A

B. 10

Explanation: For the || operator, the right operand is not evaluated, if the left operand is evaluated as true.

76
Q

Can a switch control variable be a double?

A

No! Because a double is an ‘estimation’ thus it can only be char, byte, short, int, or String

77
Q

Analyze the following code fragments that assign a boolean value to the variable even.

Code 1:
if (number % 2 == 0)
even = true;
else
even = false;

Code 2:
even = (number % 2 == 0) ? true: false;

Code 3:
even = number % 2 == 0;

A. Code 2 has a compile error, because you cannot have true and false literals in the conditional expression.
B. Code 3 has a compile error, because you attempt to assign number to even.
C. All three are correct, but Code 1 is preferred.
D. All three are correct, but Code 2 is preferred.
E. All three are correct, but Code 3 is preferred.E. All three are correct, but Code 3 is preferred.

A

E. All three are correct, but Code 3 is preferred.
Explanation: Code 3 is the simplest. Code 1 and Code 2 contain redundant code.

Code efficiently!

78
Q

What is the syntax of conditional expressions?

A

boolean-expr ? expr1 : expr2;

79
Q

Three types of loops

A

while, do-while, and for loops

80
Q

While vs do-while

A

While checks before iteration, do-while checks after iteration

81
Q

What is the syntax of the do-while loop?

A

do {
Statement(s);
} while (loop-continuation-condition)