INTRODUCTION II Flashcards

1
Q

Define programming

A

Programming is the process of creating a set of instructions that tell a computer how to perform a task

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

What are the advantages of inheritance

A

Promotes reusability
Code is reliable since it has already been tested and debugged
Effort and time is saved

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

What are the advantages of encapsulation

A
  • Encapsulation protects an object from unwanted access by clients.
  • Encapsulation allows access to a level without revealing the complex details below that level.
  • It reduces human errors.
  • Simplifies the maintenance of the application
  • Makes the application easier to understand.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the advantages of polymorphism

A

It helps the programmer to reuse the codes, i.e., classes once written, tested and implemented can be reused as required. Saves a lot of time.

Single variable can be used to store multiple data types.

Easy to debug the codes.

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

What are the advantages of abstraction

A

Encapsulation protects an object from unwanted access by clients.
Encapsulation allows access to a level without revealing the complex details below that level.
It reduces human errors.
Simplifies the maintenance of the application
Makes the application easier to understand.

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

Explain the difference between encapsulation and data abstraction as used in object oriented programming

A

Abstraction- Problems are solved at the design level
Encapsulation- Problems are solved at the implementation level

In abstraction, implementation complexities are hidden using abstract classes and interfaces. While in encapsulation, the data is hidden using methods of getters and setters.

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

Explain the difference between polymorphism and inheritance as used in object-oriented programming

A

Inheritance is basically applied to classes. Whereas polymorphism is basically applied to functions or methods.

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

Briefly explain any two different types of inheritance supported in OOP

A
  1. Single-When a class extends another one class only then we call it a single inheritance.
  2. Multiple Inheritance- one class extending (Or inherits) more than one base class.
  3. Multilevel inheritance -one can inherit from a derived class, thereby making this derived class the base class for the new class.
  4. Heirachical -one class is inherited by many sub classes
  5. Hybrid inheritance is a combination of Single and Multiple inheritance.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Briefly explain the different programming paradigms

A

Imperative: Programming with an explicit sequence of commands that update state.
Declarative: Programming by specifying the result you want, not how to get it.
Structured: Programming with clean, goto-free, nested control structures.
Procedural: Imperative programming with procedure calls.

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

what are constructors in java?

A

A Java constructor is special method that is called when an object is instantiated. In other words, when you use the new keyword. The purpose of a Java constructor is to initializes the newly created object before it is used

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

Code excerpt of polymorphism

A
public class Animal{
   ...
   public void sound(){
      System.out.println("Animal is making a sound");   
   }
}
public class Horse extends Animal{
...
    @Override
    public void sound(){
        System.out.println("Neigh");
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Code excerpt of abstraction

A
abstract class Shape{
	// code
}

public class Sports implements Shape

[
]

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

Code excerpt of encapsulation

A
class Account {
    private int account_number;
    private int account_balance;
    public void show Data() {
        //code to show data 
    }
    public void deposit(int a) {
        if (a < 0) {
            //show error 
        } else
            account_balance = account_balance + a;
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Using a code segment (s), explain the usage of keyword super in Java programming.

A

The super keyword refers to superclass (parent) objects. It is used to call superclass methods, and to access the superclass constructor. The most common use of the super keyword is to eliminate the confusion between superclasses and subclasses that have methods with the same name.

class Vehicle
{
    int maxSpeed = 120;
}
/* sub class Car extending vehicle */
class Car extends Vehicle
{
    int maxSpeed = 180;
    void display()
    {
        /* print maxSpeed of base class (vehicle) */
        System.out.println("Maximum Speed: " + super.maxSpeed);
    }
}
/* Driver program to test */
class Test
{
    public static void main(String[] args)
    {
        Car small = new Car();
        small.display();
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain the difference between throw and throws as used in OOP

A
  1. Point of Usage
    The throw keyword is used inside a function. It is used when it is required to throw an Exception logically. The throws keyword is used in the function signature. It is used when the function has some statements that can lead to exceptions.
  2. Exceptions Thrown
    The throw keyword is used to throw an exception explicitly. It can throw only one exception at a time. The throws keyword can be used to declare multiple exceptions, separated by a comma. Whichever exception occurs, if matched with the declared ones, is thrown automatically then.
  3. Syntax
    Syntax of throw keyword includes the instance of the Exception to be thrown. Syntax wise throw keyword is followed by the instance variable. throw new ArithmeticException(“/ by zero”); Syntax of throws keyword includes the class names of the Exceptions to be thrown. Syntax wise throws keyword is followed by exception class names. public static void main(String[] args)throws InterruptedException
How well did you know this?
1
Not at all
2
3
4
5
Perfectly