Doubt related object

can we make object outside the main method? why we have used this keyword in stack using array in all methods like in size method ,top method and in other also ?

You CAN create objects outside of main, but inside some OTHER method.

we have used this keyword to indicate that we are using the property of class…whenever an object calls any of its member function then the reference of the object is implicitly passed using the this keyword…
consider this example…

class A{
int a;
void seta(int a){
    this.a=a;//if i dont write this then compiler will get confused as we have a local variable named as a also
}
}

can we create object inside constructor also?

probably you can intialize objects inside constructors

class B{
}
class A{
   B b;
   A(){
       b=new B();
    }
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.