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?
- What does Java option -Xmx stand for? [duplicate]
- How do I convert a String to an int in Java?
- What does Java option -Xmx stand for? [duplicate]
- Is there an invisible character that is not regarded as whitespace?
- Problem with gif with transparent background
- Finding white rectangle in an image
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- How to convert nanoseconds to seconds using the TimeUnit enum?
- Search for words with telephone numbers from 2-3-4 tree
- Using or ‘|’ in regex [duplicate]
- How to format strings in Java
- What is the difference between x86 and x64
- && (AND) and || (OR) in IF statements
- How to use the toString method in Java?
- What is a NullPointerException, and how do I fix it?
- What exactly is Apache Camel?
- Unable to find valid certification path to requested target – error even after cert imported
- Unable to find valid certification path to requested target – error even after cert imported
- What is the equivalent of the C++ Pair
in Java? - Java – Convert integer to string [duplicate]
- Getting random numbers in Java [duplicate]
- What is an instance variable in Java?
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- Java: “error: cannot find symbol”
- How does the Java ‘for each’ loop work?
- What is a StackOverflowError?
- How to uninstall Eclipse?
- Is GNU’s Java Compiler (GCJ) dead? [closed]
- How does System.out.print() work?
- How do I “decompile” Java class files? [closed]
- How do I determine whether an array contains a particular value in Java?
- How to initialize an array in Java?
- How does the Java ‘for each’ loop work?
- Java 8 Iterable.forEach() vs foreach loop
- Initialize part of an array in java
- How can I solve Exception in thread “main” java.lang.NullPointerException error [duplicate]
- How to split a string in Java
- What does “Could not find or load main class” mean?
- Why am I getting a NoClassDefFoundError in Java?
- How to avoid “ConcurrentModificationException” while removing elements from `ArrayList` while iterating it? [duplicate]
- Eclipse/Maven error: “No compiler is provided in this environment”
- How do I compare strings in Java?
- What is reflection and why is it useful?
- Implementing UML diagram to Java [closed]
- How to round a number to n decimal places in Java
- Using Pairs or 2-tuples in Java [duplicate]
- How do I create a file and write to it?
- Could not reserve enough space for object heap
- When to use LinkedList over ArrayList in Java?
- How to convert a char to a String?
- Difference between Arrays.asList(array) and new ArrayList
(Arrays.asList(array)) - What is the proper way to handle a NumberFormatException when it is expected?
- What causes “Unable to access jarfile” error?
- How do you create a dictionary in Java? [closed]
- Reading a plain text file in Java
- Error unable to access jarfile C:\Jar
- Where is JRE 11? [duplicate]
- In laymans terms, what does ‘static’ mean in Java? [duplicate]
- How to convert/parse from String to char in java?
- Reverse a string in Java
- Static Classes In Java
- Is there any doubly linked list implementation in Java?