Objects & Constructors | Selenium Forum
M
Posted on 18/07/2016
1) In all your videos, object is created in MAIN function. what happens if object is created at CLASS level? can you please explain

2) What does it mean if STATIC is used before creating object? for e.g. name of class is TEST

STATIC test a=new test()
test a = new test()

what is difference between above 2?

3) In CONSTRUCTORS, we are able to call all static & non-static functions, static & non- static variables WITHOUT creating any object? Is it correct?

M
Replied on 19/07/2016

[quote:a2ea8fop]1) In all your videos, object is created in MAIN function. what happens if object is created at CLASS level? can you please explain[/quote:a2ea8fop]
yeah you can do it.


[quote:a2ea8fop]) What does it mean if STATIC is used before creating object? for e.g. name of class is TEST[/quote:a2ea8fop]
https://en.wikipedia.org/wiki/Static_variable
http://www.javatpoint.com/static-keyword-in-java


[quote:a2ea8fop]3) In CONSTRUCTORS, we are able to call all static & non-static functions, static & non- static variables WITHOUT creating any object? Is it correct?[/quote:a2ea8fop]
[color=#FF0000:a2ea8fop]
Constructors are kind of a method with no return type.[/color:a2ea8fop]
If they should be compared to methods, I would say constructors are closer to non-static methods (since there is indeed a this reference inside a constructor).

Given this view, it should be clear to you why a static method can call a constructor without any problems.
http://stackoverflow.com/questions/10513633/static-method-access-to-non-static-constructor