Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Method or Class initialization

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 08-03-2010
Member
 
Join Date: Dec 2009
Posts: 192
Method or Class initialization
  

Hello,
I have a small question for you, why in our code we must use a method of initialization of variables? which is it better to use a method or class initialization? and how to encode and integrate this method? Any help on this is highly appreciated. Thanks in advance.

Reply With Quote
  #2  
Old 08-03-2010
Member
 
Join Date: Nov 2009
Posts: 335
Re: Method or Class initialization

Hello,
What do you want exactly? Nothing much included in your post, more information on what you want is needed. What do you call a method of initialization of variables? If you mean the class constructor, you must do. I do not understand your question. If you have tried some code the same ten please post the code so that we can understand what exactly do you want.
Reply With Quote
  #3  
Old 08-03-2010
Member
 
Join Date: Dec 2009
Posts: 192
Re: Method or Class initialization

Hello,
I have a class that contains methods, these methods take an argument or arguments they are declared as global variable or class I returned to the hand. Then my goal to create such a method of initializing all the variables. I guess I am correct here with the concept of the object oriented programming and the java programming language. If I am in correct then please guide me correctly.
Reply With Quote
  #4  
Old 08-03-2010
Member
 
Join Date: Nov 2009
Posts: 446
Re: Method or Class initialization

Hello,
I have a code with me, see if this helps you
Code:
Public class myclass {
String v1, v2;

Public myclass(){
   v1 = vald1;/ / eg "me"
   v2 = vald2;
}
/ / rest of code
}
See if the following example helps, if not then you can post your error and then we will try to solve your problem.
Reply With Quote
  #5  
Old 08-03-2010
Member
 
Join Date: Dec 2009
Posts: 202
Re: Method or Class initialization

Hello,
I am new to java programming language, but still I have code which may interest you. Just have a look at it
Code:
class Initialization{
	Public int chapprox(float app) throws NumberFormatException, IOException{
		BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.System.out.println("approximation"+ + app"% Generates error type '1 'to improve the order of the elements");
		int fsen = Integer.parseInt(buff.readLine());
		return fsen;
		}
	Public String choiceVariable() throws IOException{
		System.out.System.out.println("Enter a var the following variables:+ cm.variables().variableName());
BufferedReader buff2 = new BufferedReader(new InputStreamReader(System.in));
String var =(String)buff2.readLine();
		return var;
	}
	Public double choicePercent() throws NumberFormatException, IOException{
		System.out.System.out.println("Enter the%");
BufferedReader ch = new BufferedReader(new InputStreamReader(System.in));
		double per = Double.parseDouble(ch.readLine());
		return per;
	}
Reply With Quote
  #6  
Old 08-03-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Method or Class initialization

Hello,
If you want to do that, it will not work for two reasons:
- Initialization this no, we can not access an instance from a static class.
- Your methods must be static, and then creates a new Initialization().
Here are two examples showing this
Code:
Initialize init = new Iitialisation();
init.choiceVariable();
Or see this
Code:
Public static String choiceVariable(){
...
}
 
...
 
Initialization.choiceVariable();
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Method or Class initialization"
Thread Thread Starter Forum Replies Last Post
How to call a method in another class in Java kannudhal Software Development 4 28-10-2010 09:29 AM
Static method in Abstract class Anthony12 Software Development 6 12-08-2010 10:22 AM
Set a class with method get() Miles Runner Software Development 5 09-02-2010 01:12 AM
Abstract class method overloading problem ISAIAH Software Development 5 16-01-2010 10:18 AM
Class <T> adapt a method based on T Badrunath Software Development 3 05-12-2009 03:30 PM


All times are GMT +5.5. The time now is 01:53 AM.