0% found this document useful (0 votes)
72 views3 pages

Practice Questions

This document contains 14 practice questions related to object-oriented programming, databases, and programming concepts. The questions cover topics such as object-oriented programming features, encapsulation, multi-threading, method overloading and overriding, static variables and methods, the final keyword, interfaces, abstract classes, recursion, pass-by-reference vs pass-by-value, the stack and heap, SQL commands, database joins, indexing, and immutable objects.

Uploaded by

Java
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views3 pages

Practice Questions

This document contains 14 practice questions related to object-oriented programming, databases, and programming concepts. The questions cover topics such as object-oriented programming features, encapsulation, multi-threading, method overloading and overriding, static variables and methods, the final keyword, interfaces, abstract classes, recursion, pass-by-reference vs pass-by-value, the stack and heap, SQL commands, database joins, indexing, and immutable objects.

Uploaded by

Java
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PRACTICE QUESTIONS

1.

What is object-oriented programming? What are two key features of object-oriented programming?

2.

What is encapsulation?

3.

What is multi-threaded computing? What are some of the dangers of multi-threaded computing and
how can they be mitigated?

4.

What is method overloading? What is method overriding?

5.

What is a static variable? Can methods and classes be static? Why would you want to make a static
variable/method/class?

6.

What does the final keyword do? Can methods and classes be final? Why would you want to make a
final variable/method/class?

7.

What is an interface? What is an abstract class? Can you instantiate an interface or abstract class?
Why would you want to use an abstract class?

8.

What is recursion? Which is faster recursion or iteration?

9.

What is the difference between pass-by-reference and pass-by-value functions?

10. What is the difference between the stack and the heap?
11. What is DML? What is DDL? What is DCL?
12. If I have two tables A and B where B has a foreign key to A, what join would I use so that the result
has all records from A (even if there is no related record in B) and all related records from B?
13. In databases, what does indexing do?
14. What is an immutable object?

ANSWER KEY
1.

What is object-oriented programming? What are two key features of object-oriented programming?
Object-oriented programming is programming focused on manipulating data through objects. Objects
contain elements and methods to store and manipulate data. Two key features of object-oriented
programming are inheritance (objects inherit elements and method from parent objects) and
polymorphism (ability for an object to act as another, similar object).

2.

What is encapsulation? How is encapsulation implemented?


Encapsulation is the practice of hiding (or exposing) elements and methods of objects from external
objects. Encapsulation is typically implemented using the keywords public (any and all objects can use the
element/method), private (only the implementing class can use the element/method) and protected (only
the implementing class and all child classes can use the element/method).

3.

What is multi-threaded computing? What are some of the dangers of multi-threaded computing and
how can they be mitigated?
Multi-threaded computing is computing in which multiple processing threads are used to complete a single
task. This typically makes the task much faster. One big danger of multi-threaded computing is the
manipulation of shared resources (resources that must be shared across multiple threads). Some ways this
danger can be mitigated is the use of locks/semaphores and/or assigning priority scores to threads.

4.

What is method overloading? What is method overriding?


Method overloading is creating a new method with the same method name, but accepting different
parameters. Method overriding is creating a new method with the same method signature as a parent class
method, but assigning the method priority (i.e. the new method will be used instead of the parent method).

5.

What is a static variable? Can methods and classes be static? Why would you want to make a static
variable/method/class?
A static variable is a variable that, once declared, exists throughout the lifetime of the program. Methods
and classes can be static. You would want to make a variable static if several instances of a class/process
must use the variable in its current state (e.g. maintaining a list of logged-in users across multiple instances
of a controller). Methods and classes could be made static to avoid having to instantiate a new instance
every time a simple method wants to be invoked.

6.

What does the final keyword do? Can methods and classes be final? Why would you want to make a
final variable/method/class?
The final keyword makes the particular variable/class/method unchangeable and un-overridable. Methods
and classes can be made final. You would want to make a variable final to avoid it being modified by
external code (e.g. certain codes your program rely will want to be final). Methods would be made final if
you do not want their functionality to be overridden by a sub-class. Similar argument for final classes.

7.

What is an interface? What is an abstract class? Can you instantiate an interface or abstract class?
Why would you want to use an abstract class?
An interface is a contract that a class signs. An interface contains method signatures that the implementing
class must define. The methods in an interface have no implementation. An abstract class is similar to an
interface, except that an abstract class may implement any or all of the methods. Neither an interface nor an
abstract class can be instantiated. A good example of wanting to use an abstract class is implementing
mammals: all mammals eat and move in different ways, but all give live birth.

8.

What is recursion? Which is faster recursion or iteration?


Recursion is when a method invokes itself. Iteration is faster as recursion requires activation records to be
made to keep-track of the method calls, but recursion is typically easier to use in complex problems than
iteration would be.

9.

What is the difference between pass-by-reference and pass-by-value functions/methods?


Pass-by-reference functions have parameters that are references of the supplied inputs. Pass-by-value
functions have parameters that are copies of the supplied inputs.

10. What is the difference between the stack and the heap?
The stack is used for static memory allocation and the heap is used for dynamic memory allocation. The
stack is assigned-to typically at compile time and the heap at runtime. Simply put, local variables within a
function are stored in the stack. Variables that are returned by functions are typically stored in the heap.
11. What is DML? What is DDL? What is DCL?
DML, DDL and DCL all refer to database SQL commands. DML stands for data-manipulation language
and encapsulates the commands such as SELECT, INSERT, UPDATE, DELETE, etc. DDL stands for
data-definition language and encapsulates the commands such as CREATE, ALTER, DROP, etc. DCL
stands for data-control language and encapsulates all commands that provide permissions such as GRANT.
12. If I have two tables A and B where B has a foreign key to A, what join would I use so that the result
has all records from A (even if there is no related record in B) and all related records from B?
Left outer join.
13. In databases, what does indexing do?
An index is used to make finding data in specified columns very quick. With an index the database engine
does not have to search through all rows, starting from the first, to find records for a query; it can actually
start in the middle of the data file to reduce the amount of searching.
14. What is an immutable object?
An immutable object is an object that cannot have its state changed. Typically, in order to manipulate an
immutable object, the object has methods that return a modified copy of itself (e.g. string.toUpper() returns
a copy of the string in all upper-case).

You might also like