Java midterm Flashcards
(17 cards)
What are the three pillars of OOP?
- 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
What is an object?
- 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
What is meant by the terms object attributes and behaviours?
- 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 is a constructor method different from a regular method?
- 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 are method overloading and overriding different?
- 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
What is an Abstract class used for?
- 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”
List some key points of Polymorphism?
- 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
What is an interface?
- 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
What are the two main uses of interfaces in Java?
- 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.
What is an exception?
- 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
What is a class?
- A class is a collection of code that contains the instructions for building an object.
- Think of this as the recipe
What is meant by the “contract” that is imposed on a class that implements an interface
- When implementing the interface you must fulfill the contract and Override any abstract method in the code
What’s the difference between checked and unchecked expressions?
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 do you deal with checked exceptions?
- Option 1: Confess to the JVM using “throws”
- Option 2: Try-Catch Block
What does static mean?
- 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
Difference between Abstract and Concrete?
- 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.
What is an aggregate class?
An aggregate class is just a class whose object can be a data member in another class