Submitted Questions

  • Why is that the final variable has to be initialized as soon as it is declare?

    Star Read Best Answer

    Editorial / Best Answer

    r.praveenkumar  

    • Member Since Oct-2007 | Aug 1st, 2008


    when a variable is declared as final we cant change its value again. we use final variable to declare a constant so when we declare a variable as final and if we were allowed to not to give its value at the time of declaration it would not make sense so people who designed java made mandatory to give the value when we declare a final variable. then only it will be sensible.
    final PI=3.14;
    then we cant change PI's value. think if the above statement do not contain a vl it would not make sense.

    Rohit Verma

    • Jul 10th, 2012

    Like any variable, a final variable can also be first declared and then assigned a value. But it can be only assigned a value once and only once ( as its final variable ). for example :- final Strin...

  • 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

    bharathnav  

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

    techbuz

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