| | |
Doing operations from different object help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hello. Im new to Java. I don't know much about Java's codes but I have a good background in C. Im using NetBeans 6.7.
I have this code:
I want to do an operation of integer x from another object then print it in Main. I can't get the code to run. The compiler is underlining the two "test" in statement "test x = new test();"
I have this code:
java Syntax (Toggle Plain Text)
package javaapplication1; public class Main { public int x = 3; public int test(){ x += 4; return x; } public static void main(String[] args) { test x = new test(); System.out.print("Hello World" + x.test); } }
the code you currently have is trying to construct a test object, but test is simply a method you call. therefore, you can simply say , furthermore when you are printing the result, is it simply
java Syntax (Toggle Plain Text)
x = test();
java Syntax (Toggle Plain Text)
x
silliboy, a silly mistake.
Data member x and method test are instance memebers of class.
Data member x and method test are instance memebers of class.
java Syntax (Toggle Plain Text)
package javaapplication1; public class Main { public int x = 3; // Instance field public int test() // Instance method { x += 4; return x; } public static void main(String[] args) { //Create an instance of class Main Main p=new Main(); System.out.print("Hello World" + p.test()); } }
![]() |
Similar Threads
- how to create the dynamic object using C# (C#)
- is conversion from void pointer to class object pointer valid?? (C++)
- Writing a Program using "pass-by-reference" functions. (C++)
- Shared Memory Object Access (C++)
- object reference not set to instance of object+axis2 (Java)
- Python class object - another strange behaviour (Python)
- Please help me to convert a simple C++ program into an object-oriented one. (C++)
- different minOccurs for different operations? (XML, XSLT and XPATH)
- [B]problem accessing object(s) in vector [/B] (Java)
- Object Oriented Design (PHP)
Other Threads in the Java Forum
- Previous Thread: java date validation
- Next Thread: pricing example project
Views: 229 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code color compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool keyword linux list loop map method methods mobile netbeans newbie number object oracle pong print problem producer program programming project read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






