Answered Questions

  • Overriding Methods

    Suppose a Super Class method throws an exception and this method is Overriden in the subclass with no exception. Now if you create a super class reference that has a subclass object. This throws a compile time error, Why?

    Star Read Best Answer

    Editorial / Best Answer


    • Member Since Oct-2008 | Oct 13th, 2008

    "Suppose a Super Class method throws an exception and this method is Overriden in the subclass with no exception. Now if you create a super class reference that has a subclass object. This throws a compile 
    Latest Answer: Because at run time, the super class will compiled first, so it will gives the run time error. ..."

    if the object has been created to the subclass and both the methods are non static then the method we overriden doesn't produce any errors or exceptions.


    • Dec 23rd, 2011

    throws exception in super class doesnt affest over-riding:code eg as follows: "java public class Ride{ void clay(){ System.out.println("am in base class"); } public static voi...

  • Null keyword

    Is null a keyword? if not what is it?

    Star Read Best Answer

    Editorial / Best Answer


    • Member Since Jun-2008 | Jun 14th, 2008

    Capital N, Null is not a keyword or a reserved word.

    All small letters, null is not a keyword either. but, it's a reserved word. you cannot use null as follows:

    String null = "a";

    null means that a reference is not pointing to any object.


    • Aug 17th, 2009

    Null is not a keyword but null is reserved literal. null is the default value for instance variable.String str = null;means instance variable str does not hold reference of any object.

  • difference between throw and throws

    What exactly is the difference between between throw and throws? If both are used for the same purpose then why are both needed instead of one?

    Star Read Best Answer

    Editorial / Best Answer


    • Member Since Jun-2008 | Jun 15th, 2008

    hi there,
    throw:the throw keyword is used to throw the exception manually,that is when you feel a particular line in your code, when executed is capable of having some exception then you use throw keyword as:
    throw new MyException(arguments if any);
    this leads to instantiating of the MyException class and exception is thrown

    throws: this is to be used when you are not using the try catch statement in your code but you know that this particular class is capable of throwing so and so exception(only checked exceptions).in this you do not use try catch block but write using the throw clause at appropriate point in  you code and the exception is thrown to caller of the method and is handeled by it. eg:

    void trouble()throws IOException,any other exceptions just separate them with commas.......
       /* throw statement at appropriate step,
        no need to use try catch here,exception would be thrown to caller and u should    provide try catch block to handle exception there else this process cotinues further till
       appropriately it is handeled or prog terminates abruptly */

    this is called as HANDLE OR DECLARE RULE  i.e either u handle exceptions using try catch block or by declaring them


  • Output of Java Program

    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


    • Member Since Jan-2008 | 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  :-)


    • Jun 2nd, 2018

    (v) Compilation Error


    • Mar 14th, 2018

    (v) Compilation Error

  • what type of access specifiers can we use for local variables?


    • Aug 18th, 2009

    Local variable cannot be modified using any of the acceess specifiers means you can not write private or protected or public before them.Local variables are by default (implicitly)  private no need to make it explicitly private or protected or public otherwise it won't compile.

  • What is the result of the following?public static void main(String[] args)

    choice:a)compilation errorb)runtime errror Or what is the result?


    • Jun 16th, 2008

    It will result in a compilation error because first thing is that you have not written method body ,else if you don't want to write method body then declare it abstract and terminate it using semi colon.

  • What is the argument type of a program's main() method

    A program's main() method takes an argument of the String[] type.


    • Jun 16th, 2008

    you write public static void main(String args[])so the argument type isstring and whatever input you give asjava abs "asd" 1then all the 3 arguments are stored int he corresponding string fo...

  • What is the catch or declare rule for method declarations

    If a checked exception may be thrown within the body of a method, the method musteither catch the exception or declare it in its throws clause.


    • Jun 15th, 2008

    this rule is actually for handling the exceptions:that is there are two ways by ehich u can handle the exception :1:either you use the try catch statement and enclose the appropriate code in the try c...