|
| |||||||||
| Tags: abstract class, class, function, interface, method |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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. |
|
#2
| |||
| |||
| 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. |
|
#3
| |||
| |||
| 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. |
|
#4
| |||
| |||
| 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
} |
|
#5
| |||
| |||
| 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;
} |
|
#6
| |||
| |||
| 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(); Code: Public static String choiceVariable(){
...
}
...
Initialization.choiceVariable(); |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 10:29 AM |
| Static method in Abstract class | Anthony12 | Software Development | 6 | 12-08-2010 11: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 |