Define programming
Programming is the process of creating a set of instructions that tell a computer how to perform a task
What are the advantages of inheritance
Promotes reusability
Code is reliable since it has already been tested and debugged
Effort and time is saved
What are the advantages of encapsulation
What are the advantages of polymorphism
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.
What are the advantages of abstraction
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.
Explain the difference between encapsulation and data abstraction as used in object oriented programming
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.
Explain the difference between polymorphism and inheritance as used in object-oriented programming
Inheritance is basically applied to classes. Whereas polymorphism is basically applied to functions or methods.
Briefly explain any two different types of inheritance supported in OOP
Briefly explain the different programming paradigms
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.
what are constructors in java?
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
Code excerpt of polymorphism
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");
}
}Code excerpt of abstraction
abstract class Shape{
// code
}public class Sports implements Shape
[
]
Code excerpt of encapsulation
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;
}
}Using a code segment (s), explain the usage of keyword super in Java programming.
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();
}
}Explain the difference between throw and throws as used in OOP