(.readLine() method) of BufferedReader class
Overrided
whats the difference of this
Code :
String readLine(boolean ignoreLF) throws IOException {
StringBuffer s = null;
int startChar;
to this
Code :
public String readLine() throws IOException {
return readLine(false);
}
question:
1.) what is the first code? a method? why is it doesnt have any modifiers?
2.) when everytime im calling a .readLine() method. which of the two am i reffering to?
Re: (.readLine() method) of BufferedReader class
You are referring to the second one with no arguments in it.
The first code block you posted is the actual readLine method which takes a boolean if it should ignore linefeed or not.
The second code block is a convenience method which just calls the other one with a default value of false passed in.
// Json
Re: (.readLine() method) of BufferedReader class
but i try to make a method like the first one...
Code :
public class NewClass {
String word() {
return "My Method";
}
public String word() { //method word is already defined
return word();
}
}
bit confuse due to some curiosity :)
Re: (.readLine() method) of BufferedReader class
They are both the same, if you give one of the parameters then they are different. Look up function overloading.
Chris
Re: (.readLine() method) of BufferedReader class
Code :
public class NewClass {
String word(boolean x) { // i add some parameters here..
return "My Method";
}
public String word() { //method word is already defined
return word();
}
}
ahh ,.
and i can access both of them... .
why do we have to define such methods that has different purposes with the same name? or the same identifier?
and like what have sir Json told me... when everytime im calling the .readLine() method im only calling the second one... (the one with modifier)
so whats the purpose of the first one?? (the one without modifier).
Re: (.readLine() method) of BufferedReader class
Convenience, thats all :)
// Json
Re: (.readLine() method) of BufferedReader class
i change the method name of the public method word() into doIt()
Code :
String word(boolean x) {
return "My Method";
}
//if i change the method name ....
public String doIt () {
return word(); //the method word is asking for an argument
}
}
but if they are the same.. everythings fine....
hmm..?:confused:
Re: (.readLine() method) of BufferedReader class
in your last set of methods, word requires a boolean parameter x.
Also, when you had this:
Quote:
Code :
public class NewClass {
String word(boolean x) { // i add some parameters here..
return "My Method";
}
public String word() { //method word is already defined
return word();
}
}
Here, word() will never return because it's always calling itself, not the other word. It should be this:
Code :
public class NewClass {
String word(boolean x) { // i add some parameters here..
return "My Method";
}
public String word() { //method word is already defined
return word(true); // or false, it doesn't matter in this case
}
}