INTRODUCTION TO OOP Flashcards

1
Q

Describe object-oriented programming

A

A method of programming based on a hierarchy of classes with well defined and cooperating objects.

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

What is an object?

A

An object is an executable copy of a class. It can also be referred to as an instance

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

What are states and behaviors, give real world examples

A

For a dog:
states (breed, color, age, hungry) - nouns and adjectives
behaviors (barking, eating, fetching) -verbs

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

What are fields and methods?

A
  • An object stores its state in fields and exposes its behavior through methods.
  • Methods operate on an object’s internal state and IMPLEMENT object-to-object communication.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a class?

A

A blueprint from which objects are created. It defines the data and the methods to work on the data

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

What is a package and what is its importance?

A
  • A package is a namespace that organizes a set of related classes and interfaces. (It is like different folders on our personal computer.)
  • Packages are important for organization.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Where can one find a complete listing of all packages, interfaces, classes, fields, and methods supplied by the Java SE platform.

A

The Java Platform API Specification

*application programming interface

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 group of related methods with empty bodies.
  • Methods form the object’s interface with the outside world; e.g remote buttons, computer keyboards, e.t.c.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some characteristics of OOP?

A
  1. Encapsulation
  2. Inheritance
  3. Abstraction
  4. Polymorphism
  5. Message passing
  6. Garbage collection
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Define encapsulation

A
  • This is a concept that enables the hiding unnecessary details in classes and only providing a clear and simple interface for working with them.
  • It is also called information hiding.
  • An object must provide its users only with the essential information for manipulation, without the internal details.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is inheritance

A
  • Inheritance is a concept in OOP that enables new objects to take on the properties of existing objects.
  • Object-oriented programming allows classes to ASSUME commonly used state and behavior from other classes.
  • Inheritance is an “is a” relationship eg a dog is a animal; therefore it inherits the characteristics common to animals
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the names of classes involved in inheritance?

A
  • A class that is used as the basis for inheritance is called a superclass or base class.
  • A class that inherits from a superclass is called a subclass or derived class.
  • In Java, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is abstraction?

A

The process of representing essential features without including background details or explanations / The process of defining the essential concepts while
ignoring the inessential details.

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

What are the types of abstraction?

A
  • Data Abstraction
  • Functional Abstraction
  • Object Abstraction
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is polymorphism?

A

This is the ability to present the same interface for differing underlying forms.

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

What are the different types of polymorphism?

A
  • Method overloading

* Method overriding

17
Q

Describe garbage collection in OOP

A

This is a form of automatic memory management whereby the garbage collector attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program.

18
Q

What is a variable?

A

A variable is a container that holds values that are used in a Java program

19
Q

What are the different types of variables?

A
  • Instance variables (non-static fields)
  • Class variables (static fields)
  • Local variables
  • Parameters
20
Q

Describe an instance variable (non-static field)

A

• Objects store their individual states in “non-static fields” (fields declared without the static keyword.)
• Non-static fields are also known as instance variables because their values are unique to each instance of a class (object)
• E.g., the different ages of new objects in a Registration system.
*immediately after class

21
Q

Describe a class variable (static fields)

A
• A class variable is any field declared with the static modifier.
• There is exactly one copy of this variable in existence in a class regardless of how many times the class has been instantiated.
• The key word static is usually used to indicate static variables.
*immediately after class
EG static int data = 30;
22
Q

Describe local variables

A

• These are variables that store temporary states.
• There is no special keyword designating a variable as local.
• Local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.
*Found within a method

23
Q

What are parameters and where are they found?

A

• These are variables found within the parenthesis of different structs within a program.
• Examples of the structs where parameters are found include:
• Methods
• Constructors
*Found within ()

24
Q

Give example (source code) showing the different types of variables

A
public class A  
{  
    static int m=100;/static variable  
    void method()  
    {    
        int n=90;/local variable    
    }  
    public static void main(String args[])  
    {  
        int data=50;/instance variable    
    }  
}//end of class
25
Q

What are the rules for naming variables?

A
  1. Variable names are case-sensitive.
  2. Can begin with a letter, underscore or $
  3. Subsequent characters for a variable may be letters, digits, dollar signs, or underscore characters.
  4. When choosing a name for your variables, use full words instead of cryptic abbreviations
    (self-documentation)
  5. Variable names consisting of more than one word should be named, e.g. carSpeed or car_speed
26
Q

What are the eight primitive data types in java?

A
  • Byte
  • Short
  • Integer
  • Long
  • Float
  • Double
  • Boolean
  • Character
27
Q

What do data types determine?

A

the values it may contain, their sizes plus the operations that may be performed on it.

28
Q

Define states and behaviors

A

States/attributes- built in characteristics of an object

behaviors- predefined functions

29
Q

Briefly explain at least 4 object-oriented design concepts.

A

encapsulation, abstraction, inheritance, and polymorphism

30
Q

why is java suitable for studying advanced OOP / What are the advantages of java?

A
  1. Java is simple. It is easy to learn, understand and debug.
  2. It makes it possible to write reusable and modular code
  3. Java reduces security threats and risks by avoiding the use of explicit pointers
  4. Java programs are cheap to develop and maintain as these programs are dependent on a specific hardware infrastructure to run. We can easily execute them on any machine that reduces the extra cost to maintain.
  5. Java offers a very effective boon to its users by providing the feature of platform independence that is Write Once Run Anywhere(WORA) feature.
  6. Java provides Automatic Garbage Collection run by the java virtual machine
31
Q

What are the disadvantages of java?

A
  1. Java is slow and has a poor performance due to the extra level of compilation and abstraction by the JVM.
  2. Java provides no backup facility. Java mainly works on storage and not focuses on the backup of data
  3. Java requires a significant or major amount of memory space as compared to other languages like C and C++
  4. Java codes are verbose, meaning that there are many words in it and there are many long and complex sentences that are difficult to read and understand. This can reduce the readability of the code.