What is the output of the following program, when tested under jdk 5.0class exceptiondemo{ public static void main(string[] args) { int a[] = new int[] {1,2,3,4,5}; try{ system.Out.Prinltln(a[6]); } catch(exception e) { system.Out.Println("catching exception ..."); ...
What is the output of the following Java program
Public interface i1{static string x="inside i1";public void somemethod();}class a implements i1{ public static void main(string args[[]){ system.Out.Println("calling i1 var ..."+i1.X);}}
Answered by: abuthahir.d
View all answers by abuthahir.d
Member Since Jan-2008 | Answered On : Apr 14th, 2008
Compilation error due to 2 reasons.
1. All variables defined in the Interfaces are implicitly public static final. So need not specify "Static" in interface.
2. If any of the member functions of a Interface is not Overriden , a compilation error will be thrown
It is right that you dont need to explicitly define a varible static but if you do so then it will not give compliler error..
Compilation error will come because you must have to override the abstract method of the implememted interface. After the implementation of the abstract method the program will compile and run properly and print "inside l1".
What is the output of the following program?Class a{ public static void main(string[] s) { system.Out.Println(s[1] + s[2] + s[3]);}}Java a 12345options(i) 1(ii) 12(iii)1234(iv)234(v) compilation error
Answered by: abuthahir.d
View all answers by abuthahir.d
Member Since Jan-2008 | Answered On : Apr 14th, 2008
Khadar , i tried this code . it gives that exception
for the foll reason :
when u give a CLA(command line argument) , it will be inserted in the index 0 of the array and then will proceed to 1 ,2 ....
so as per the question , "12345" will be at s[0] . and length of that aray will be 1when u try to access s[1] , we are trying for 2nd element which is unavailable.....
Hope this answers u :-)
exception will be come when using class: java.lang.ArrayIndexOutOfBoundsException: 1 , because 12345 input comes at s[0] places and when we are getting s[1] it come java.lang.ArrayIndexOutOfBounds...
v) Compilation Error
Implement interface using polymorphism
How an interface can be implemented using polymorphism?Why multiple inheritence is not used in Java?
I think your question is how to achieve Runtime Polymorphism using using interface.then the answer is :interface MyInf{ void show();}class A implements ...
Polymorphism means "one form many actions". Lets say, a class Test implements an interface ITest. Accordingly,public interface ITest{ public void testMethod();}//a class implemen...
When does thread throws illegal state of exception?Explain with two scenarios?
Any attempt to change the status after the thread has been started, throws an IllegalThreadstateException.Scenerio 1If a thread has already started and you try to call method setDaemon(boolean) on thr...
Hi,There are one scenario where we can use it as shown below.Two threads within the JVM both gain access to the same object. One thread invalidates the object and then the other thread attempts ...
What is nullpointer exception how it will be reduced
There are many reasons to get a Null pointer Exception . Burn it in ur Brain : NullPointerException can occur only on OBJECTS . not primitives.the above said answer holds a good example .Example 2: &n...
I can give you example
if you create string array and you not assing any value for that string object.
when you want print this array the JVM give Null pointer Exception
Output is "catching exception"
This will give error that exception caught already