In which memory does the object is allocated on JVM?

What is Object-Oriented Programming?

What are the advantages of OOP?

Objects vs Primitives?

Provide examples of creating objects in Java.

How is an object created, explain in detail?

What happens when an object is Instantiated more than once?

How are methods in an object are invoked?

What are constructors and its uses?

What happens behind the scene when we use ‘new’ for invoking a constructor?

What are the default values for all the variables in Java?

Is it valid to use an instance variable inside a class to use before initialized?

What is a default constructor?
The default constructor is a no-argument constructor that is provided by Java if you define a class without explicitly defining any constructors.
Can we instantiate an object with the default constructor when it is not defined in the class?

What is an initialization block?
It is a block of code that is run every time an object is instantiated.
Does the placement of initialization blocks inside a class matter? Explain with example.
In the below code as the initialization block is placed before the definition “Green”, it is overridden and it gets value “Green”.
Note: Irrespective of placement of initialization block, if a value is defined inside a constructor like in below “Blue”, that will be executed last and it gets “Blue”.
public class Car {
{
color = "Red";
}
String color = "Green";
Car() {
//color = "Blue";
} }``` In the below code as the initialization block is placed after the definition "Green", it gets value "Red".
public class Car {
String color = "Green";
Car() {
//color = "Blue";
}
{
color = "Red";
} } ~~~In below code color variable gets “Blue” as initial value, as always constructor execution is done at the end.
public class Car {
String color = "Green";
Car() {
color = "Blue";
}
{
color = "Red";
}
}