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. 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 :
Ans. Volatile is an instruction that the variables can be accessed by multiple threads and hence shouldn't be cached. As volatile variables are never cached and hence their retrieval cannot be optimized.
Help us improve. Please let us know the company, where you were asked this question :
Ans. No. Even though "this" would mean a reference to current object id the method gets called using object reference but "this" would mean an ambiguity if the same static method gets called using Class name.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Static methods can be called using instance references wherein this would have made sense but static method can also be called using Class name wherein this would mean nothing and hence forbidden.
Help us improve. Please let us know the company, where you were asked this question :
Methods , Variables , Initialization Blocks and Outer Classes and nested Classes.
Methods , Variables , Initialization Blocks and Outer Classes.
Methods , Variables , Initialization Blocks and nested Classes.
Which of the following cannot be marked static ?
Constructors , Classes ( Outer ) , Classes ( nested ), Interfaces , Local variables , Inner Class methods and instance variables.
Constructors , Classes ( Outer ) , Interfaces , Local variables , Class variables , Class Methods , Inner Class methods and instance variables.
Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.
Constructors , Classes ( Outer ) , Classes (Nested), Interfaces , Local variables , Inner Class methods and instance variables.
Q38. In majority of the situations it won't make much sense whether you append this with the instance method call.Can you tell a situation wherein this keyword would make sense in a instance method ?
Ans. Within instance method of the parent class that has other multiple methods that have been overridden by the derived classes.
In such case a simple method call from the common method will always be made to the method definition in the parent class. But If we use this.methodCall , this will be polymorphic and will be made to the respective derived object overriding method.
Help us improve. Please let us know the company, where you were asked this question :
Q39. Which of the following is not the use of this keyword ?
a. Passing itself to another method b. To call the static method c. Referring to the instance variable when local variable has the same name d. Calling another constructor in constructor chaining
Ans. To call the static method
Help us improve. Please let us know the company, where you were asked this question :
Q40. Which of the following is not true for final variables ?
a. They cannot be changed after initialization b. They can be initialized within static method c. They can be declared and initialized together at the same place d. They can be initialized within constructor
Ans. They can be initialized within static method
Help us improve. Please let us know the company, where you were asked this question :