<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Originally posted by Nisheeth Kaushal:
Hi Friends
I have a difficulty here in this particular quesiton
class Vehicle {
String str ;
public Vehicle() {
}
public Vehicle ( String s ) {
str = s;
}
}
public class Car extends Vehicle {
public static void main (String args[] ) {
final Vehicle v = new Vehicle ( " Hello" );
v = new Vehicle ( " How are you");
v.str = "How is going";
System.out.println( "Greeting is : " + v.str );
}
}
A) Compiler error while subclassing the Vehicle
B) Compiler error , you cannot assign a value to final variable
B) Prints Hello
C) Prints How is going
This class is executing easily, but i think that the subclass will see for a default constructor, and if it does not find it, it will throw an error.
This particular program is producing error, but b'coz of fina variable not for the reason which i want.
Please help me,
Thanx in advance.
Nisheeth
second you asked about the default constructor for Vehcile. well it is there, though it is empty but that is ok.
public Vehcile() {}
but this default constructor is not being invoked. only the constructor which takes string parameters is invoked. (2 times)
Originally posted by mark stone:
yes you are right that the statement
final Vehcile v = new Vehcile.......
is not correct. You make a class final where you declare it.
second you asked about the default constructor for Vehcile. well it is there, though it is empty but that is ok.
public Vehcile() {}
but this default constructor is not being invoked. only the constructor which takes string parameters is invoked. (2 times)
i hope now question is clear.
Rob
SCJP 1.4