More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. final keyword have meaning only to referenced and not the value. It means that the specified reference cannot be dereferenced. It doesn't control the value assigned to the memory that's being referenced. This is the reason that final object references doesn't mean that the object is immutable but means that the reference cannot be changed to point to new object.
In case of primitive types too, when we assign a reference to another, values are passed and not the object reference, and hence a new placeholder is created in memory with the same value. That is why final to that context means that you cannot change the assigned memory and there is no way we can have that memory place have another value.
Help us improve. Please let us know the company, where you were asked this question :
Ans. All Keywords , modifiers ( public , static , final etc ) as well as non modifier keywords ( for, if,switch etc ) are reserved words in java and hence cannot be used as identifiers. Along with keywords , there are few literals that have predefined meaning and hence cannot be used as identifiers, these are true , false and null.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Goto statement results in unstructured jumps in control from one code location to another and hence makes the code very difficult
to read , maintain and debug. Moreover Goto can always be replaced using other statements like break / continue and hence results in structured movement of programming control.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Keyword is a reserved word that has a pre defined meaning for the compiler and hence cannot be used as an identifier, for example - final, private , for etc.
Identifier is the name given by the programmer to a programming construct, for example - class and method names etc.
java Keywords cannot be used as an identifier in java.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Keywords are the reserved words that have a pre defined meaning for a compiler whereas modifiers are the type of keywords that modifies the state or definition of a programming construct.
for, while are keywords but not modifiers.
private , public , final , abstract etc are keywords as well as modifiers.
Help us improve. Please let us know the company, where you were asked this question :
Ans. static keyword is used to specify that the respective programming construct ( method , variable ) belongs to the class and not to its instance and is supposed to be shared by all instances of the class.
Help us improve. Please let us know the company, where you were asked this question :
Q22. Does compiler treats it differently if we don't prefix this to the member element and its implicit as its the only variable available with that name ?
Ans. It makes no difference whether we add this to the variable or not. The only use of this is in the cases where there are multiple variables with the same name and we want to distinguish between the member variable and local variable. In case this is not added ,this is automatically added by the compiler in the byte code.
Help us improve. Please let us know the company, where you were asked this question :
Static methods belong to the class and not the objects. They belong to the class and hence doesn't fit properly for the polymorphic behavior.
A static method is not associated with any instance of a class so the concept of overriding for runtime polymorphism using static methods is not applicable.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes.we cannot access them directly but we can access them using object reference.Static methods belong to a class and not objects whereas non static members are tied to an instance. Accessing instance variables without the instance handler would mean an ambiguity regarding which instance the method is referring to and hence its prohibited.
Help us improve. Please let us know the company, where you were asked this question :