![]() |
| Home | Tech FAQ | Interview Questions | Placement Papers | Tech Articles | Learn | Freelance Projects | Online Testing | Geeks Talk | Job Postings | Knowledge Base | Site Search | Add/Ask Question |
![]() Related Questions Which of the following 2 methods executes faster ?class Trial { String _member; void method1() { for(int i=0;i<2048;i++) { _member += "test"; } } void method2() { String temp; for(int i=0;i<2048;i++) { temp += "test"; } _member = temp; } } (a) method1() (b) method2() (c) Both method1() and method2() takes same time for execution (b)Accessing method variables requires less overhead than accessing class variables. (a) Latest Answer : an exception of NumberFormat will be thrown ... By default, Strings to functions are passed using the method(a) Call by Value (b) Call by Reference (c) Strings cannot be passed to function (b)String is a class defined in java.lang and in java all classes are passed by reference. What is the output of following program ?class Test { public static void main(String args[]) { for(int i=0;i<2;i++) { System.out.println(i); } } }(a) Goes into infinite loop (b) 0,1 (c) 0,1,2 (d) None (a) How many String objects are created by the following statements ?String str = " a+b=10 "; trim(str) str.replace(+,-);(a) 1 (b) 2 (c) 3 (d) 4 (c)Strings are immutable. So, for each String operation, one new object is generated. Latest Answer : Interface is design on which class is built.Interface is a java defined type. ... Latest Answer : yes answer is final it wou't give chance to other to modify. it prevant to other to chace the class. ... What is the better way of writing the Constructor with 2 parameters in the following code:class Test What is the better way of writing the Constructor with 2 parameters in the following code:class Test { int x,y; Test(int a) { //Code for very complex operations will be written //in this place x=a; } Test(int a, int b) { //Code for very complex operations will be written //in this place (same code as in above constructor) x=a; y=b; } }
Sponsored Links
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||