General Interview Questions - Neethahiremath/Wiki GitHub Wiki

How to get heap dump What are the different garbage collectors available, and which is used in project?


Guess the output of the program:

class TestCLass {

	{
		System.out.println("Inside Block");
	}

	static {
		System.out.println("Inside Static Block");
	}

	TestCLass() {
		System.out.println("Inside Constructor of Class");
	}

	public static void main(String[] args) {

		TestCLass obj = new TestCLass();

		System.out.println("*******************");
		
		TestCLass obj1 = new TestCLass();

	}

}


Guess the output:


public class Animal {

    void display(){
        System.out.print("Animal class");
    }
}



public class TestClass extends Animal{
    @Override
    public void display() {
        System.out.print("hi");
    }

    public static void main(String[] args) {
        TestClass test = new TestClass();
        test.display();

        Animal animal = new TestClass();
        animal.display();

        Animal animal1 = new Animal();
        animal1.display();

        TestClass test1 = new Animal();
        test.display();
    }
}


can u use kafka without zookeeper


write code in java 8 to output a map from given list of values

[abc, cat,cot,bat] =>

{
a : [abc],
c: [cat,cot]
b: [bat]
}


public class TestClass extends Animal {
    @Override
    public void display() {
        System.out.print("hi");
    }

    public void display(long a) {
        System.out.print("long" + a);
    }

    public void display(int a) {
        System.out.print("int" + a);
    }

    public void display(short a) {
        System.out.print("short" + a);
    }

    public static void main(String[] args) {
        TestClass test = new TestClass();
        test.display(12);

        Animal animal = new TestClass();
        animal.display();

        Animal animal1 = new Animal();
        animal1.display();

      /*  TestClass test1 = new Animal();
        test.display();*/
    }
}

guess the output:

/*
Overloading
applicable within the class
if parameter dataType passed does not have exact match, it looks for parent dataType and call the method
It calls method based on object reference and not on object. example : 
animal a = new Dog()
since a is assigned to animal, it looks for method having animal as parameter
*/

public class TestClass  {

    public void display(Animal a) {
        System.out.print("Animal called");
    }

    public void display(Dog a) {
        System.out.print("Dog is called");
    }

    public static void main(String[] args) {

        TestClass testClass = new TestClass();
        Animal animal = new Animal();
        Animal animal1 = new Dog();

        Dog dog = new Dog();

        testClass.display(dog);

        testClass.display(animal);
        testClass.display(animal1);

    }
}