well in class level you can only define attributes of that class, cant do any processing which you are doing in classA and classB. Processing can only be done in method.
Just add main method make objects there
public class Hello { // value / method public static String staticValue; public String nonStaticValue; public void main(String[] args){ Hello hello = new Hello(); Hello.staticValue = "abc"; hello.nonStaticValue = "xyz"; Hello hello2 = new Hello(); // here staticValue = "abc" Hello.staticValue; // will have value of "abc" hello2.nonStaticValue; // will have value of null } }
Main method is entry point of any program in java. Dont worry if you are confused where this main method is called.
Related Posts:
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- What is a StackOverflowError?
- How to uninstall Eclipse?
- How do I determine whether an array contains a particular value in Java?
- How can I solve Exception in thread “main” java.lang.NullPointerException error [duplicate]
- Why am I getting a NoClassDefFoundError in Java?
- How to avoid “ConcurrentModificationException” while removing elements from `ArrayList` while iterating it? [duplicate]
- Using Pairs or 2-tuples in Java [duplicate]
- Is there a way to convert all comments into javadoc comments? [Eclipse/Java]
- Reverse a string in Java
- “Char cannot be dereferenced” error
- Explanation on Integer.MAX_VALUE and Integer.MIN_VALUE to find min and max value in an array
- Exception in thread “main” java.lang.StackOverflowError
- Best way to convert an ArrayList to a string
- Rock, Paper, Scissors Game Java
- How do I reverse an int array in Java?
- Why should a Java class implement comparable?
- How Long Does it Take to Learn Java for a Complete Newbie?
- Java JDK – possible lossy conversion from double to int
- Global variables in Java
- Lombok and Maven
- java Arrays.sort 2d array
- what is the difference between `public class` and just `class`?
- Copying and modifying array elements
- How to send Https Post request in java
- What is the purpose of a listener in Java?
- Sorting HashMap by values
- Will Arrays.sort() increase time complexity and space time complexity?
- How can I concatenate two arrays in Java?
- Difference between spring @Controller and @RestController annotation
- How do I use a delimiter with Scanner.useDelimiter in Java?
- Sort a single String in Java
- Difference between slf4j-log4j12 and log4j-over-slf4j
- Java, “Variable name” cannot be resolved to a variable
- What is Java String interning?
- What condition does while(true) test? When is it true and false?
- How/where to download openjdk/openjre for windows [duplicate]
- copy a 2d array in java
- Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException
- Generating all permutations of a given string
- imageio.IIOException: Can’t read input file
- Difference between OpenJDK and Adoptium/AdoptOpenJDK
- Compile failed; see the compiler error output for details
- Java: Rotating Images
- Invalid character constant in java
- How to pass a function as a parameter in Java?
- ResultSet exception – before start of result set
- The activity must be exported or contain an intent-filter
- How to set JAVA_HOME environment variable on Mac OS X 10.9?
- How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error
- channel 3: open failed: connect failed: Connection refused
- Java Currency Number format
- How to create a generic array in Java?
- Print a boolean value with printf
- Meaning of @Resource annotation
- How to solve error lossy convertion from int to char?
- What does “error: ‘.class’ expected” mean and how do I fix it
- Printing the stack values in Java
- Import a custom class in Java
- The specified child already has a parent. You must call removeView() on the child’s parent first (Android)
- HTTP Status 500 Error instantiating servlet class
- How to convert the following json string to java object?
- Java: How to set Precision for double value?
- Any way to declare an array in-line?
- java.io.StreamCorruptedException: invalid stream header: 54657374
- How to cast ArrayList<> from List<>
- Best way to “negate” an instanceof
- How to send HTTP request in java?
- How to take input as String with spaces in java using scanner
- Address already in use: JVM_Bind java
- java.lang.ClassNotFoundException:com.mysql.jdbc.Driver [duplicate]
- How can I check if a value is of type Integer?
- Using regex to match any character except =
- what is the difference between doGet() and doPost() in term of the flow?
- Java 3D Game Engine?
- How to cast ArrayList<> from List<>
- Using insertion sort for descending order?
- What is the home directory for JDK?
- java.lang.ClassNotFoundException: org.postgresql.Driver, Android
- Java – Change int to ascii
- Adding JPanel to JFrame
- Append a single character to a string or char array in java?
- Java printf formatting to print items in a table or columns
- A fatal error has been detected by the Java Runtime Environment: SIGSEGV, libjvm
- java.lang.IllegalStateException: Failed to introspect Class
- ShoppingCart.Java Program Assignment
- White spaces are required between publicId and systemId
- Http status 401 This request requires HTTP authentication (). in tomcat 6
- Get integer value of the current year in Java
- How to make the division of 2 ints produce a float instead of another int?
- Java Console Prompt for ENTER input before moving on [duplicate]
- Can’t load IA 32-bit .dll on a AMD 64-bit platform
- Android Studio 2.2.3: Gradle project sync failed. Basic functionality (e.g. editting, debugging) will not work properly
- How to draw a circle with given X and Y coordinates as the middle spot of the circle?
- In Java, how do I parse XML as a String instead of a file?
- Java Returning method which returns arraylist?
- String cannot be resolved to a type – Java RAD
- IntelliJ IDEA “The selected directory is not a valid home for JDK”
- Simple timeout in java
- Eclipse message saying List cannot be resolved to a type