Since the main
method is static
and the fxn()
method is not, you can’t call the method without first creating a Two
object. So either you change the method to:
public static int fxn(int y) {
y = 5;
return y;
}
or change the code in main
to:
Two two = new Two();
x = two.fxn(x);
Read more on static
here in the Java Tutorials.
Related Contents:
- What exactly is Spring Framework for? [closed]
- Is there a destructor for Java?
- Get an OutputStream into a String
- How can I increment a date by one day in Java?
- Change Name of Import in Java, or import two classes with the same name
- Best XML parser for Java [closed]
- Mockito verify order / sequence of method calls
- How to format LocalDate to string?
- How can I read input from the console using the Scanner class in Java?
- Pass a local file in to URL in Java
- Execute method on startup in Spring
- Why am I getting a “401 Unauthorized” error in Maven?
- JPA getSingleResult() or null
- How to extract epoch from LocalDate and LocalDateTime?
- Cleanest way to build an SQL string in Java
- does System.currentTimeMillis() return UTC time?
- Is the creation of Java class files deterministic?
- Intellij Idea – automatically add final keyword to the generated variables
- Java2D: Increase the line width
- Java collections convert a string to a list of characters
- How to change value of ArrayList element in java
- getLocationOnScreen() vs getLocationInWindow()
- Eclipse is confused by imports (“accessible from more than one module”)
- How to fix unchecked call warning in Java?
- Is it ok to remove newline in Base64 encoding
- Why does a Try/Catch block create new variable scope?
- Is package by feature approach good? [closed]
- Default maximumPoolSize for HikariCP
- Is there a difference between main(String args[]) and main(String[] args)?
- Javadoc in JDK 8 : Invalid “self-closing element not allowed”
- Would a Java HashSet’s contains() method test equality of the strings or object identity?
- How do you debug Java Applets?
- How to make spring boot never issue session cookie?
- How to set the log level to DEBUG during Junit tests?
- JPA OneToMany and ManyToOne throw: Repeated column in mapping for entity column (should be mapped with insert=”false” update=”false”)
- Is there a way to run a method/class only on Tomcat/Wildfly/Glassfish startup?
- Test if file exists
- Hibernate: get entity by id
- How do I add package level annotations or edit package-info.java?
- PKIX path building failed: unable to find valid certification path to requested target
- loop on list with remove [duplicate]
- What’s the difference between program arguments and VM arguments?
- Flyway repair with Spring Boot
- How to speed up Java VM (JVM) startup time?
- Throw exception vs Logging
- android device id confusion
- Compile, Provided, APK – Android dependency scope
- how to convert `content://media/external/images/media/Y` to `file:///storage/sdcard0/Pictures/X.jpg` in android?
- java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String() in Java EE application
- Fastest way to write to file?