What is an object? What is a class?
An object is an entity that has a state and behavior.
A class is a template used to create objects and define object data method and types.
What is Method Overriding - usage and rules?
Subclass that has the same method as declared in the parent class.
Usage: provide the specific implementation of a method which is already provided by its superclass.
Rules: must be the same name as the parent class, same parameter as the parent class, and must be an Is-A relationship
What are the 3 types of loops?
while loop
for loop
do... while loop
What is a "final keyword"?
used to restrict the user.
What is a "String"?
a sequence of characters
What is a "constructor" and when are they called?
A constructor is a block of codes.
It is called with an instance of the the object is created and memory is allocated.
What are the advantages of "encapsulation"?
1. read-only or write-only
2. provides control over data
3. achieve data hiding
4. easy to test
What is the enhanced loop introduced for?
To transverse collection of elements including rays
What is the usage of "super" keyword? (3)
- used to refer immediate parent class instance variable
- used to invoke immediate parent class method
- used to invoke immediate parent class constructor
What are the advantages of "packages" and how do you access them?
- used to categorize the classes and interfaces so they can easily be maintained
- access protection
- removes naming collision
How to access:
- import package.*;
- import package.classname;
- fully qualified name
What are advantages of inheritance?
1. Method Overriding (so runtime polymorphism can be achieved)
2. Code Reusability
What is "Method Overloading" and the different ways to overload a method?
A class that has multiple methods having same name but different in parameters.
1. by changing number of arguments
2. by changing the data type
Whaat type of loop is useful when you know how many times a task is to be repeated?
For Loop
What is a "static keyword" and what is it applied?
used for memory management
- variable (class variable)
- method (class method)
- block
- nested class
What are the advantages and disadvantages to an "Array"?
advantages include Code Optimization and random access
disadvantages include size limit.
What are advantages of OOP over POP?
-OOPs make development and maintenance easier
-OOPs provide data hiding
What are Access Modifies and the 4 types?
specifies accessibility (scope) of a data member, method, constructor or class
4 types include private, default, protected, and public
What are the definitions for each loop?
While loop - repeatedly executes a target statement as long as a given condition is true
For loop - repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times
Do... While Loop - similar to while loop, except is guaranteed to execute at least one time.
What is this usage of "this" keyword? (6)
- used to refer current class instance variable
- used to invoke current class method (implicitly)
- used to invoke current class constructor
- passed as an argument in the method call
- passed as an argument in the constructor call
- used to return the current class instance from the method
What are the similarities between an interface and a class? (4)
- interface can contain any number of methods
- interface is written in a file with a .java extension, with the name of the interface matching the name of the file.
- the byte code of an interface appears in a .class file
- interfaces appear in packages, and the corresponding bytecode file must be in a directory structure that matches the package name
True or false? (must get both right)
A constructor is invoked implicitly.
A method must not have a return type.
True
False
What are the 4 OOP pilars and definitions of each?
Inheritance - one object acquires all the properties/behaviors of a parent object.
Polymorphism - ability of an object to take on many forms.
Encapsulation - process of wrapping code and data together.
Abstraction - process of hiding the implementation details and showing only functionality to the user.
What kind of loop is this an example of?
public class Test {
public static void main(String args []) {
int x = 10;
while (x < 20 ) {
System.out.print("value of x : " + x );
x++;
System.out.print("\n");
}
}
}
While Loop
True or False?
A static variable is used to refer to the common property of all objects.
true
True or False?
The first element of he array is stored at the 0 index.
true