Accessing a class inside other class?


Accessing a class inside other class?



Class 1 -> Page 1 locators
Class 2 -> Page 2 locators


Class 1{
Class 2{

}
}



I am navigating to Class 1 and Class 2 by below method:


Class1 class1= new Class1()
Class1.Class2 class2= class1.new Class2()



This is the way mostly acccessing the Class 2 which is working fine most of the case..



But for single test case, I dont want to instantiate Class 1 because it will not go to page 1 and directly goes to Page 2.



Is there anyway we can access Class2 directly without creating object for Class 1.





Why do you need nested classes? Why isn't Class2 static?
– cricket_007
Jul 2 at 13:16




1 Answer
1



No.



A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private. Static nested classes do not have access to other members of the enclosing class. As a member of the OuterClass, a nested class can be declared private, public, protected, or package private. (Recall that outer classes can only be declared public or package private.)



...or in the same page:



An instance of InnerClass can exist only within an instance of OuterClass and has direct access to the methods and fields of its enclosing instance.



Ref: https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.