Object Oriented Programming Flashcards
What is inheritance?
Inheritance is an object oriented programming technique that lets you use one class as the basis for another.
What is an interface?
An interface is a set of methods and fields that a class must provide to implement an interface.
What is a constructor?
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.
What are the members of a class?
The members of a class are the fields and methods defined in the class body.
What is a field?
A field is a variable that’s defined in the body of a class, outside any of the class’s methods.
What does the term public mean?
It means that it is accessible to other classes.
What does the term private mean?
It means that is is accessible to only the class that is is created in.
How do you make a private field or method accessible to other classes?
You must make a getAccessor.
What is a getAccessor?
A getAccessor is a method that retrieves a field value.
What is a setAccesor?
A setAccessor is a method that sets a field value.
What does overloading methods mean?
It means that you may have two methods in the same class, with the same name as long as they have different parameter types.
What are the 3 ways to use a this statement.
To call to another constructor in the class, to refer to a class variable, and to refer to an object.
What is an initializer?
An initializer is a lonely block of code that’s place outside any method, constructor, or other block of code.
Name 4 facts on initializers.
- If there is more than one initializer in a class they are executed in the order of which they appear.
- Initializers are executed before any constructors.
- Static initializers initialize static fields.
- Initializers are sometimes used with anonymous classes.
What is a static method?
A static method is a method that isn’t associated with an instance of a class. Instead, the method belongs to the class itself.
Name 5 ways of using static.
- To create constants or other values that aren’t associated with instances of a class.
- To count how many instances have been created.
- To assign reference or numbers to each new object instance.
- To provide an alternative way to create an instance of a class.
- To provide utility functions that aren’t associated with objects at all.
How do you prevent an instance?
By creating a private constructor.
What is a static initializer?
A static initializer is an initializer that initializes static fields. Ex) static { }
What does the math method abs do?
It returns the absolute value of a number
Basic format: Math.abs(-26.7); gives 26.7
What does the math method ceil do?
It rounds the number up
Basic format: Math.ceil(7.4); gives 8
What does the math method floor do?
It rounds the number down
Basic format: Math.floor(7.8); gives 7
What does the math method max do?
Gives the maximum of the two numbers
Basic format: Math.max(8.2,5.2); gives 8.2
What does the math method min do?
Gives the lesser of the two numbers
Basic format: Math.min(8.2,5.2); gives 5.2
What does the math method pow do?
Puts the first number to the power of the second number
Basic format: Math.pow(5,3); gives 125
What does the math method sqrt do?
Returns the square root of a number
Basic format: Math.sqrt(9); gives 3