Object Oriented Programming Flashcards

1
Q

What is inheritance?

A

Inheritance is an object oriented programming technique that lets you use one class as the basis for another.

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

What is an interface?

A

An interface is a set of methods and fields that a class must provide to implement an interface.

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

What is a constructor?

A

A constructor is a block of code that’s similar to a method but is run to intialize an object when an instance is created.

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

What are the members of a class?

A

The members of a class are the fields and methods defined in the class body.

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

What is a field?

A

A field is a variable that’s defined in the body of a class, outside any of the class’s methods.

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

What does the term public mean?

A

It means that it is accessible to other classes.

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

What does the term private mean?

A

It means that is is accessible to only the class that is is created in.

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

How do you make a private field or method accessible to other classes?

A

You must make a getAccessor.

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

What is a getAccessor?

A

A getAccessor is a method that retrieves a field value.

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

What is a setAccesor?

A

A setAccessor is a method that sets a field value.

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

What does overloading methods mean?

A

It means that you may have two methods in the same class, with the same name as long as they have different parameter types.

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

What are the 3 ways to use a this statement.

A

To call to another constructor in the class, to refer to a class variable, and to refer to an object.

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

What is an initializer?

A

An initializer is a lonely block of code that’s place outside any method, constructor, or other block of code.

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

Name 4 facts on initializers.

A
  1. If there is more than one initializer in a class they are executed in the order of which they appear.
  2. Initializers are executed before any constructors.
  3. Static initializers initialize static fields.
  4. Initializers are sometimes used with anonymous classes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a static method?

A

A static method is a method that isn’t associated with an instance of a class. Instead, the method belongs to the class itself.

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

Name 5 ways of using static.

A
  1. To create constants or other values that aren’t associated with instances of a class.
  2. To count how many instances have been created.
  3. To assign reference or numbers to each new object instance.
  4. To provide an alternative way to create an instance of a class.
  5. To provide utility functions that aren’t associated with objects at all.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you prevent an instance?

A

By creating a private constructor.

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

What is a static initializer?

A

A static initializer is an initializer that initializes static fields. Ex) static { }

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

What does the math method abs do?

A

It returns the absolute value of a number

Basic format: Math.abs(-26.7); gives 26.7

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

What does the math method ceil do?

A

It rounds the number up

Basic format: Math.ceil(7.4); gives 8

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

What does the math method floor do?

A

It rounds the number down

Basic format: Math.floor(7.8); gives 7

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

What does the math method max do?

A

Gives the maximum of the two numbers

Basic format: Math.max(8.2,5.2); gives 8.2

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

What does the math method min do?

A

Gives the lesser of the two numbers

Basic format: Math.min(8.2,5.2); gives 5.2

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

What does the math method pow do?

A

Puts the first number to the power of the second number

Basic format: Math.pow(5,3); gives 125

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

What does the math method sqrt do?

A

Returns the square root of a number

Basic format: Math.sqrt(9); gives 3

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

What does the super keyword do?

A

It calls to the superclasses constructor to use in the subclass.

27
Q

What is a final class?

A

A final class is a class that can’t be used as a base class.

28
Q

What is a final method?

A

A final method is a method that can’t be overridden by a subclass.

29
Q

How do you override a method?

A

By using creating a method with that same name and same paramaters as the method in the super class.

30
Q

What does protected keyword mean?

A

It means that it is accessible to sub classes but no other classes.

31
Q

How do you create a subclass?

A

By using the extends keyword

Basic format: public class className extends className { }

32
Q

What is the instanceof operator used for?

A

To determine an object’s type.

33
Q

What does the term polymorphism mean?

A

The term polymorphism refers to the ability of Java to use the base class variables to refer to subclass objects, to keep track of which subclass an object belongs to:and to use overridden methods of the subclass, even though the subclass isn’t known when the program is compiled.

34
Q

What does the term late binding mean?

A

Late binding means that when the compiler can’t tell for sure what type of object a variable references, it doesn’t hard-wire the method calls when the program is compiled. Instead, it waits until the program is executing to determine exactly which method to call.

35
Q

What is the Throwable class?

A

The root of the exception hieracrhy is the Throwable class. This class represents any object that can be throw with a throw statement and caught with a catch clause.

36
Q

What is the Error class?

A

A subclass of throwable class, that represents serious error conditions that reasonable programs can’t recover from. The subclasses of this class represent the specific types of errors that can occur.

37
Q

What is the Exception class?

A

A subclass of the Throwable class, represents an error condition that most programs should try to recover from.

38
Q

What is the RunTimeException class?

A

A subclass of the Exception class, represents unchecked exceptions.

39
Q

How do you create an exception class?

A

By defining a class that extends one of the classes in the Java exception hierarchy.

40
Q

What is an abstract method?

A

An abstract method is just a prototype for a method, a return type, a name, a list of parameters, and (optionally) a throws clause. It has no body.

Basic format: public abstract int hit(int batSpeed);

41
Q

What is an abstract class?

A

A class that contains atleast one abstract method, and must be declared abstract on the class declaration.

Basic format: public abstract class Ball {

42
Q

Name two advantages interfaces have over inheritance.

A
  1. Interfaces are easier to work with than inheritance, because you don’t have to worry about providing any implementation details in the interface.
  2. A class can extend only one other class, but it can implement as many interfaces as you need.
43
Q

Name two things a class must do to implement an interface.

A
  1. It must specifiy and implements clause on it’s class declaration.
  2. It must provide and implementation for every method declared by the interface.
44
Q

Can a class implement more than one interface?

A

yes.

45
Q

You can pass an interface as a type, meaning you can use it as a parameter.

A

Extending a class and creating an instance of an object through an instance of a class, and passing it as an object and instance. in interface class this would be the parameter Dealable name. The interface name is Dealable.

46
Q

What is a subinterface?

A

An interface that extends an existing interface.

47
Q

What is a superinterface?

A

A base interface for another interface.

48
Q

What is callback?

A

A programming technique in which an object lets another object know that the second object should call one of the first object’s methods whenever a certain event happens.

49
Q

What is an event listener?

A

The first object in a callback.

50
Q

What is an event source?

A

The second object in a callback.

51
Q

What is a marker interface?

A

An interface that doesn’t have any members. It’s purpose is to identify a class belonging to a set of classes that possess some capability or have some characteristics in common.

52
Q

What is the Object class?

A

The class that every other class inherits, including all the classes in the Java API and every class you create yourself.

53
Q

What is the Class class?

A

The class that is used to get information about an object’s type.

54
Q

What does the protected Object clone() method do?

A

Returns a copy of this object.

55
Q

What does the boolean equals(Object obj) method do?

A

Indicates wether this object is equal to the obj Object.

56
Q

What does the protected void finalize() method do?

A

It’s called by the garbage collector when the object is destroyed.

57
Q

What does the class getClass() method do?

A

Returns a class Object that represent this object’s runtime class.

58
Q

What does int hashCode() method do?

A

Returns this object’s hash code.

59
Q

What does the void notify() method do?

A

It is used with threaded applications to wake up a thread that’s waiting on this object.

60
Q

What does the void notifyAll() method do?

A

It is used with threaded applications to wake up all threads that are waiting on this object.

61
Q

What does the String toString() method do?

A

Returns a String representation of this object.

62
Q

What does the void wait() method do?

A

Causes this object’s thread to wait until another thread calls notify or notifyAll.

63
Q

What do the void wait(Long timeout) and void wait(Long timeout, int nanos) methods do?

A

They are variations of the basic void wait() method.