Java Flashcards

1
Q

What is Object Oriented Programming (OOPs)?

A

Is a way of organizing the code by using object-oriented principles. It models real world entities as objects which encapsulate data and behavior. Is objects talking to each other.

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

method

A

Is a building block of a object oriented program. Blueprint of definining the behavior of an object. Like what a character is able to do in a video game.

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

What is a class ?

A

Is a building block of a object oriented program. Blueprint of objects having common properties. Like a blue print of a character

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

Object

A

is an instance of a class. Is what the class is building – in a video game is basically a character

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

Method

A

Is a building block of a object oriented program. Blueprint of definining the behavior of an object. Like what a character is able to do in a video game.

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

Interface

A

It serves as a blueprint for classes. s a contract that defines a set of methods or properties that a class must implement. That cannot be instated.

// Interface declaration
interface Animal {
// Method signature
void makeSound();

// Constant
String TYPE = "Animal"; }

// Class implementing the interface
class Dog implements Animal {
// Implementing the method from the interface
public void makeSound() {
System.out.println(“Dog barks”);
}
}

public class Main {
public static void main(String[] args) {
Dog dog = new Dog();
dog.makeSound(); // Output: Dog barks
System.out.println(Animal.TYPE); // Output: Animal
}
}

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

abstraction

A

is a a blueprint for classes that cannot be instantiated directly

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

Encapsulation

A

is the bundling of data that operates into a single unit called a class. It includes
1. Data Hiding
2.Public interface
3. Data validation

// Class definition
public class Car {
// Fields
private String model;
private int year;

// Getter for model
public String getModel() {
    return model;
}

// Setter for model
public void setModel(String model) {
    this.model = model;
}

// Getter for year
public int getYear() {
    return year;
}

// Setter for year
public void setYear(int year) {
    this.year = year;
} }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Polymorphism

A

It means that different objects can use the same method or function name, but each one can act in its unique way.
1. Method overriding-it occurs when a class has multiple methods with the same name but different parameters.
class Animal {
public void makeSound() {
System.out.println(“Animal makes a sound”);
}
}

class Dog extends Animal {
@Override
public void makeSound() {
System.out.println(“Dog barks”);
}
}

public class Main {
public static void main(String[] args) {
Animal animal = new Dog(); // Polymorphism
animal.makeSound(); // Output: Dog barks
}
}

  1. Method Overloading occurs when a class has multiple methods with the same name but different parameters
    class Calculator {
    public int add(int a, int b) {
    return a + b;
    }public double add(double a, double b) {
    return a + b;
    }
    }

public class Main {
public static void main(String[] args) {
Calculator calculator = new Calculator();
int sum1 = calculator.add(2, 3); // Invokes the int version of add()
double sum2 = calculator.add(2.5, 3.5); // Invokes the double version of add()
}
}

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

Inheritance

A

It’s passing down traits from the parent class to child class.

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

JDK

A

JAVA develoment kit it contains the compiler and debugger and JRE

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

JRE

A

Java run time environment it contains the libraries and the JVM

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

What is spring boot

A

Is an open source Java framework

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

Overloading

A

it occurs when a class has multiple methods with the same name but different parameters.

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

overriding

A

occurs when a class has multiple methods with the same name but different parameters

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

What is association

A

relationship that has no ownership over another.

17
Q

What is a copy constructor ?

A

is a constructor that initializes an object through another object of the same class.

18
Q
A