java-training/src/PassByValueForEver.java
<reponame>kaushalpranav/python-ds-training<gh_stars>0import java.util.ArrayList;
import java.util.List;

public class PassByValueForEver {
    private static void testParameters(int a,boolean b, List<Integer> lst, String str) {
        a = 100;
        b = false;
        // lst.add(123);
        lst = new ArrayList<>();
        lst.add(2934);
        str = str + "world";  // "helloworld"
    }

    public static void main(String[] args) {
        Automobile automobile = new Automobile();
        automobile.setSpeed(100);
        automobile.setAmountOfFuel(100);

        // automobile = new Automobile(23, 12);

        automobile.accelerate(7);

        automobile.setSpeed(100);
        int speedOfAutomobile = automobile.getSpeed();

        Automobile automobile1 = new Automobile(100, 100);
        Automobile car = new Car(100, 100);

        List<Automobile> listOfAutomobiles = new ArrayList<>();

        // [ auto1, auto2, auto3 ]

        listOfAutomobiles.add(automobile1);
        listOfAutomobiles.add(car);

        System.out.println("==========Demo Polymorphism==========");

        System.out.println("Initial speeds of all automobiles");

        for (Automobile automobile2 : listOfAutomobiles) {
            System.out.println(automobile2.getSpeed());
        }

        System.out.println("Accelerating all the Automobiles by 10 units");

        for (Automobile automobile2 : listOfAutomobiles) {
            automobile2.accelerate(10);
        }

        System.out.println("Checking new speeds of automobiles");

        for (Automobile automobile2 : listOfAutomobiles) {
            System.out.println(automobile2.getSpeed());
        }

        System.out.println("Different versions of accelerate invoked on different automobiles");

        System.out.println("==========Start PassByValue test==========");

        int a = 1123;
        boolean b = true;

        List<Integer> lst = new ArrayList<>();
        lst.add(792);

        String str = "hello";

        PassByValueForEver.testParameters(a, b, lst, str);

        System.out.println(a);
        System.out.println(b);
        System.out.println(lst);
        System.out.println(str);

    }
}

/*
Object-Oriented Principles

Encapsulation - Grouping up related fields and methods in a class
Abstraction   - Exposing only what the class does, and not the internal implementation (like a black box)
Polymorphism  - Something that exists in multiple forms (an overrided method using inheritance)
 */