GeekInterview.com
Answered Questions

Exception handling

Asked By: khadarzone | Asked On: Apr 14th, 2008

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 ..."); ...

Answered by: kuchipudi Prasad on: May 30th, 2012

Output is "catching exception"

Answered by: sampra on: Mar 6th, 2012

This will give error that exception caught already

What is the output of the following Java program

Asked By: khadarzone | Asked On: Apr 11th, 2008

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);}}

Star Read Best Answer

Editorial / Best Answer

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

Answered by: shanu_rastogi on: Feb 3rd, 2010

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..

Answered by: sarojmohanty on: Nov 19th, 2009

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".

Output of Java program

Asked By: khadarzone | Asked On: Apr 11th, 2008

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

Star Read Best Answer

Editorial / Best Answer

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  :-)

Answered by: akii on: Apr 30th, 2013

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...

Answered by: d on: Jan 19th, 2013

v) Compilation Error

Implement interface using polymorphism

Asked By: adarsh01 | Asked On: Apr 6th, 2008

How an interface can be implemented using polymorphism?Why multiple inheritence is not used in Java?

Answered by: Sarje on: Aug 18th, 2009

I think your question is how to achieve Runtime Polymorphism using using interface.then the answer is :interface MyInf{         void show();}class A implements ...

Answered by: shouvanik1979 on: Mar 30th, 2009

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...

Illegal state of exception

Asked By: dsureshkumar28 | Asked On: Apr 3rd, 2008

When does thread throws illegal state of exception?Explain with two scenarios?

Answered by: mkgraumt on: Sep 27th, 2008

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...

Answered by: charankk on: Apr 29th, 2008

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 ...

Nullpointer exception

Asked By: vijayramd | Asked On: Mar 27th, 2008

What is nullpointer exception how it will be reduced

Answered by: abuthahir.d on: Apr 14th, 2008

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...

Answered by: shyamgosavi648 on: Apr 2nd, 2008

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              

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us: