Java midterm Flashcards

(17 cards)

1
Q

What are the three pillars of OOP?

A
  • Encapsulation: Controlled access to data (Private, Public, Protected, Default)
  • Inheritance - A class inherits attributes and methods from the super class
  • Polymorphism: The ability of an object to take on many forms. A java object that can pass more than one is A test is polymorphic
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an object?

A
  • The object has two main parts
  • It’s properties(data variables and values)
  • It’s methods (Named blocks of code that do something when called)
  • An object is what gets built in memory when the constructor method is called an object is what ets bult
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is meant by the terms object attributes and behaviours?

A
  • The data held in the object is referred to as the state of the object
  • Behaviour: The behavior of an object is defined by whatever methods have been declared in the class. It is what the object can do
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How is a constructor method different from a regular method?

A
  • A constructor method definition differs in 2 ways from all other methods in java
  • A constructor method name is always exactly the same as the class name (SO IT BEGINS IN UPPERCASE)
  • No return type is ever specified for a constructor method. What does get returned is an object of that class but we don’t specify this in the method header
  • A default constructor is not defined by the coder. It is provided by java automatically
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How are method overloading and overriding different?

A
  • Overloading is having several methods with the same name, but with different parameter lists
  • Each method has a unique signature(Combo of name and parameter list)
  • Overloaded methods are ALL DEFINED IN THE SAME CLASS
  • Method Overriding involved multiple methods with the same name and signature, but with different body code
  • (!T) These methods are defined in different classes in a class hierarchy
  • Usually a method is defined in a super class and Overwritten in a subclass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an Abstract class used for?

A
  • An abstract class is a super class that has so few properties that it does not make sense to instantiate an object of the class
  • In class Hierarchy the top class is the most abstract
  • As you go down the hierarchy, more variables and methods are added thus making the object more “concrete”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

List some key points of Polymorphism?

A
  • Polymorphism applies only to methods
  • In order for polymorphism to work, the objects of the subclass have to be created and referenced by a variable of the super class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an interface?

A
  • An interface is a special type of class that provides a way of describing a set of abstract public methods and constant values
  • An interface can hold data values, but by default the values will be constats. Java will automatically make the values public,static and final
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the two main uses of interfaces in Java?

A
  • If you want a large number of classes to implement some common function through a method, you can write the abstract method declaration in an interface and then have each of the classes implement the interface
  • You can simulate multiple inheritance. Often used when a class has a exhibit an “OFF BEAT” behavior not found in it’s super class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an exception?

A
  • An exception is an OBJECT that signals an error of some kind has occured in your program and bad things will happen if not dealt with
  • the benefit of exception is that it seperates code that deals with errors from the code that is executed when things are running smoothly
  • The exception object has data members that store information about the nature of the problem
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a class?

A
  • A class is a collection of code that contains the instructions for building an object.
  • Think of this as the recipe
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is meant by the “contract” that is imposed on a class that implements an interface

A
  • When implementing the interface you must fulfill the contract and Override any abstract method in the code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s the difference between checked and unchecked expressions?

A

Unchecked expressions are subclassed from the Error and Runtime class. This means the coder doesn’t have to specifically include exception handling code

-If it is a checked expression Jave will force the coder to write some code in order to deal with it

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

How do you deal with checked exceptions?

A
  • Option 1: Confess to the JVM using “throws”

- Option 2: Try-Catch Block

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

What does static mean?

A
  • A variable or method can be accessed without requiring an instantiation of the class to which it belongs.
  • You can call a method, even if you’ve never created the object to which it belongs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Difference between Abstract and Concrete?

A
  • The higher a class is in the class hierarchy the more abstract it is. The lower it is the more Concrete.
  • More Concrete methods will have more body code in the methods.
17
Q

What is an aggregate class?

A

An aggregate class is just a class whose object can be a data member in another class