Suposse you have
Class1
public class Class1 { //Your class code above }
Class2
public class Class2 { }
and then you can use Class2 in different ways.
Class Field
public class Class1{ private Class2 class2 = new Class2(); }
Method field
public class Class1 { public void loginAs(String username, String password) { Class2 class2 = new Class2(); class2.invokeSomeMethod(); //your actual code } }
Static methods from Class2 Imagine this is your class2.
public class Class2 { public static void doSomething(){ } }
from class1 you can use doSomething from Class2 whenever you want
public class Class1 { public void loginAs(String username, String password) { Class2.doSomething(); //your actual code } }
Related Posts:
- Wait for page load in Selenium
- How to get locator of current web element?
- How to open a new tab using Selenium WebDriver in Java?
- Selenium Webdriver: Element Not Visible Exception
- Test if element is present using Selenium WebDriver?
- What does “Could not find or load main class” mean?
- What does “Could not find or load main class” mean?
- How do I resolve ClassNotFoundException?
- MacOS Catalina(v 10.15.3): Error: “chromedriver” cannot be opened because the developer cannot be verified. Unable to launch the chrome browser
- Java: Multiple class declarations in one file
- element not interactable exception in selenium web automation
- what is the difference between `public class` and just `class`?
- stale element reference: element is not attached to the page document
- How do you make a deep copy of an object?
- What does .class mean in Java?
- How to identify object types in java
- implicit super constructor Person() is undefined. Must explicitly invoke another constructor?
- What is the difference between Integer and int in Java?
- Java Class File Editor
- Import a custom class in Java
- Java The method is undefined for this type
- java sort using anonymous class
- When is the finalize() method called in Java?
- Import a custom class in Java
- Error: Generic Array Creation
- Java – get the current class name?
- .class vs .java
- What is a class constant?
- Selenium — How to wait until page is completely loaded
- Why do some classes require main methods and others do not?
- Chrome Error: You are using an unsupported command-line flag: –ignore-certifcate-errors. Stability and security will suffer
- Node cannot be resolved to a type
- Selenium using Java – The path to the driver executable must be set by the webdriver.gecko.driver system property
- incompatible types: void cannot be converted to int [duplicate]
- Could not find or load main class with a Jar File
- Class Declarations for temperature program in Java
- How can I design a class named allergy?
- Reading a plain text file in Java
- Converting double to string
- What is the “continue” keyword and how does it work in Java?
- Java String new line
- What does the protected modifier mean?
- Java default constructor
- What is the meaning of “this” in Java?
- ‘Java’ is not recognized as an internal or external command
- Java: Identifier expected
- How does Java’s PriorityQueue differ from a min-heap?
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse
- How to split a String by space
- Java compile error: “reached end of file while parsing }”
- Double % formatting question for printf in Java
- in java what does the @ symbol mean?
- How to call a method in another class in Java?
- unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
- Error creating bean with name ‘entityManagerFactory’ defined in class path resource : Invocation of init method failed
- Java, “Variable name” cannot be resolved to a variable
- How to convert a Binary String to a base 10 integer in Java
- How to import a .cer certificate into a java keystore?
- Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 0 error in Java
- How can I represent a range in Java?
- How to solve error: ‘;’ expected in Java?
- Making a Java Makefile
- Android java.lang.IllegalStateException: Could not execute method of the activity
- Java error: Comparison method violates its general contract
- “Cannot create generic array of ..” – how to create an Array of Map
? - javac: file not found: first.java Usage: javac
- Eclipse Java error: This selection cannot be launched and there are no recent launches
- align text center with android
- hat is the purpose of flush() in Java streams?
- How can I convert integer into float in Java?
- How can I avoid this Ant Build error?
- Java Comparator class to sort arrays
- (The Triangle class) Design a class named Triangle that extends GeometricObject
- Cannot assign requested address using ServerSocket.socketBind
- Consider defining a bean of type ‘package’ in your configuration [Spring-Boot]
- Java – How to do floor division?
- IntelliJ – Can’t start – “JAVA_HOME does not point to a valid JVM installation”
- Empty an array in Java / processing
- Class is not Abstract and does not Override error in Java
- hibernate properties not found
- Make a simple timer in Java
- How to switch scenes in JavaFX
- Coding Conventions – Naming Enums
- Sort ArrayList of custom Objects by property
- Java better way to delete file if exists
- How to send HTTP request in java? [duplicate]
- Best way to represent a fraction in Java?
- java IO Exception: Stream Closed
- Can a normal Class implement multiple interfaces?
- What kind of Java type is “[B”?
- Is there a way to get element by XPath using JavaScript in Selenium WebDriver?
- Hibernate – Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
- How to programmatically close a JFrame
- Playing .mp3 and .wav in Java?
- Difference between jar and war in Java
- Adding image to JFrame
- Troubleshooting “The type parameter T is hiding the type T” warning
- model.addAttribute() parameters
- StringFormat for Java Boolean Operator
- JOptionPane Yes or No window