|
| |||||||||
| Tags: arguments, class, function, initiate object, method, object, parameter |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Different ways to initiate an object
Hello, Here is my code Code: Public void execution() {
op = new op;
}
Public getOperation(){
return op;
} |
|
#2
| |||
| |||
| Re: Different ways to initiate an object
Hello, I think this is called as a local variable which you have used in your code Code: op op |
|
#3
| |||
| |||
| Re: Different ways to initiate an object
Hello, In this case, your method returns nothing. You created an instance of a class that will be used throughout the life of the civil execution(). In this method so you created an instance of Operation that you registered in a local variable named operation (PS: your NullPointerException must come from the fact that there is a naming conflict because when compiling, it found that 2 variables for the compiler are different but have the same name). I hope this will help you. |
|
#4
| |||
| |||
| Re: Different ways to initiate an object
Hello, Yes, I completely agree with the above post and here is a sample example to explain the same. Code: / / Declaration of class op private op op; Public void execution2 () ( op = new op (); ) Public getOperation () ( return op; ) Last edited by SoftWore : 11-03-2010 at 12:49 PM. |
|
#5
| |||
| |||
| Re: Different ways to initiate an object
Hello, So the best thing to do is?: Code: / / Declaration of class op
private op op;
Code:
Public void execution() {
op = new op;
}
Code:
Public getOperation(){
return op;
} |
|
#6
| |||
| |||
| Re: Different ways to initiate an object
Hello, I think you can do the following Code: Public getOperation () ( return op; } Code: public op getOperation () ( return op; ) |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Different ways to initiate an object" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Ways to disable object snap in Word 2010 | M@ndy | Windows Software | 2 | 04-12-2011 08:03 PM |
| Getting HP AIO Device object server register class object failed message on my system | Donoho | Hardware Peripherals | 6 | 06-06-2011 02:34 AM |
| Scope of Object or variable in Object oriented Programming Languages | Dėfrim | Software Development | 3 | 08-01-2011 06:20 AM |
| Granting access via security group (user object vs. computer object | ikaikaokaina | Active Directory | 2 | 15-04-2010 08:31 PM |
| How many ways to create an object for class | Shanbaag | Software Development | 3 | 25-04-2009 11:08 AM |