Java - Interview Questions and Answers for 'Keywords' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2137 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Keywords' - 46 question(s) found - Order By Newest

 Q1. Which of the following combination of keywords is illegal in Java ?

a. static and transient
b. transient and final
c. static and synchronized
d. abstract and final
Core Java
Anonymous
Ans. abstract and final

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java keywords     VirtusaPolaris  IVTL InfoView Technologies      basic


 Q2. Can we access instance variables within static methods ?Core Java
Anonymous
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 :   

   Like      Discuss      Correct / Improve     java   oops   static   static methods   java keywords     Oracle


Advanced level question usually asked to senior developers , leads and architects.
 Q3. How does volatile affect code optimization by compiler?Core Java
Admin
info@buggybread.com
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 :   

   Like      Discuss      Correct / Improve     java   java keywords   volatile   synchronization   compiler optimization   variable caching   architecture     Embedded security  Driver engineer  Sokrati      expert


Frequently asked question for intermediate developers.
  Q4. What is Volatile keyword used for ?Core Java
Anonymous
Ans. Volatile is a declaration that a variable can be accessed by multiple threads and hence shouldnt be cached.

  Sample Code for volatile

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   synchronization   volatile   java keywords     ABC Ltd   Ciena  Xchanging  Square  Infoview Technologies  HCL Technologies  EPAM  GrubHub  TeleMessage  TRUSTe  Informatica  Square  Medidata Solutions  Yellow Pages  eQ Technologic  Sutra Analytics  CustomerXPs  Globant  BB Holdings  Rakuten  Booking.com  BlackRock  Qualcomm  LSI Corporation  ARM Holdings  SpaceX  Toshiba  Peapod  Amadeus  Apptio  Tivo  EchoStar  HomeAway  Syscom Technologies  Aversan  Symantec  Samsung India  Axtria  Qualcomm  CGI Group      intermediate        frequent

Try 1 Question(s) Test


 Q5. What is the use of Transient Keyword ?Core Java
Anonymous
Ans. It in Java is used to indicate that a field should not be serialized.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   serialization   transient   java keywords     Cognizant (CTS)  The Advisory Board Company      intermediate        frequent

Try 2 Question(s) Test


 Q6. What is a Final Method ?Core Java
Anonymous
Ans. A Method that cannot be overriden in the sub class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   java keywords   final   final method   overriding   basic interview question      basic        frequent

Try 1 Question(s) Test


Very Frequently asked.Favorite question in Walk in drive for many Indian service companies.
 Q7. What is a Final Class ?
Anonymous
Ans. A Class that cannot be sub classed.

  Sample Code for final class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   final   final class   java keyword   basic interview question     HCL Technologies  Tata Consultancy (TCS)  Infosys      basic        frequent


 Q8. Can we override static methods ? Why ?Core Java
Anonymous
Ans. No.

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 :   

   Like      Discuss      Correct / Improve     java   oops   static   static methods   java keywords   yes-no      intermediate        frequent


 Q9. What is "super" used for ?
Anonymous
Ans. Used to access members of the base class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   java keywords   super   basic interview question      basic        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. What is "this" keyword used for ?
Anonymous
Ans. Used to represent an instance of the class in which it appears.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   java keywords   this   basic interview question      basic        frequent


 Q11. What is "Import" used for ?Core Java
Anonymous
Ans. Enables the programmer to abbreviate the names of classes defined in a package.

  Sample Code for import

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   import   java keyword


 Q12. What is a Static import ?Core Java
Anonymous
Ans. By static import , we can access the static members of a class directly without prefixing it with the class name.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java5   static import   static   java keyword   static import     Infosys  Weather Channel  Tata Consultancy (TCS)  ePace Technologies      basic        frequent


 Q13. Why can't we use this in static context ?Core Java
Admin
info@buggybread.com
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 :   

   Like      Discuss      Correct / Improve     java   static methods   this keyword

Try 2 Question(s) Test


 Q14. Which of the following keyword is not permitted for outer class ?

a. public
b. abstract
c. final
d. protected
Anonymous
Ans. protected

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java keywords


 Q15. What is the use of static keyword in Java ?Core Java2017-01-09 13:32:24

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 :   

   Like      Discuss      Correct / Improve     static keyword     EPAM      basic        frequent


 Q16. Explain the use of "Native" keyword ?Core Java
Anonymous
Ans. Used in method declarations to specify that the method is not implemented in the same Java source file, but rather in another language

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   native   java keywords     Teradata


 Q17. Can we use "this" within static method ? Why ?Core Java
Admin
info@buggybread.com
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 :   

   Like      Discuss      Correct / Improve     java   oops   static   this keyword   this   yes no   why questions      intermediate


Rarely asked as default methods have been introduced with Java 8.
 Q18. Can we have a default method definition in the interface without specifying the keyword "default" ? Core Java
Admin
info@buggybread.com
Ans. No. Compiler complains that its an abstract method and hence shouldn't have the body.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java8   default methods   default keyword   yes-no


 Q19. 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 ? Core Java
admin
info@buggybread.com
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 :   

   Like      Discuss      Correct / Improve     java   this keyword   java keywords



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. 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
Anonymous
Ans. To call the static method

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     this   this keyword   java


 Q21. 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
Anonymous
Ans. They can be initialized within static method

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   final   final variable   java keywords


 Q22. Which of the following is false for final ?

a. Final methods cannot be overriden
b. Final methods cannot be overloaded
c. Final classes cannot be subclassed
d. Final class cannot be abstract
Anonymous
Ans. Final methods cannot be overloaded

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   final   java keyword


 Q23. Can we add more elements to an array list that has been marked as final ?

Ans. Yes, the array list can hold more elements. Final only puts the restriction that the array list reference cannot hold any other array list.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     ebay   collections   arraylist   final keyword


 Q24. Why can't we declare a class abstract as well as final ?Core Java

Ans. Abstract means that the class is only meant to be subclassed whereas final means that it cannot be subclassed so both concepts - abstract and final are actually mutually exclusive and hence not permitted together.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     abstract   final   java keywords     VirtusaPolaris


 Q25. 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 ?2016-05-29 10:18:38

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 :   

   Like      Discuss      Correct / Improve     this keyword  member elements  member variables


 Q26. Is New Keyword a method Name ?2016-06-12 20:15:01

Ans. No, Its an Operator.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     new keyword


 Q27. Name some of the Java Keywords ?Core Java2017-01-07 16:54:09

Ans. Static , Final , Synchronized, private , public , protected, volatile, transient, super, this,import , abstract,native,default (effective java 8), new

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java keywords        frequent


 Q28. Is delete a keyword in Java ?Core Java2017-01-12 11:20:42

Ans. No, delete is not a keyword in Java. Destruction of objects is taken care by Java Garbage Collection mechanism.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     delete  keywords     HCL Technologies


 Q29. Is exit a keyword in Java ?Core Java2017-01-12 11:21:28

Ans. No exit is a method to exit execution of a program.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     exit  keywords  exit a program     HCL Technologies



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q30. What is the difference between a keyword and a modifier ?Core Java2017-04-26 19:55:30

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 :   

   Like      Discuss      Correct / Improve     keyword  modifier


 Q31. Which of the following applies to Final ?

It is a keyword
It is a modifier
It is an access modifier
Core Java2017-04-26 19:56:51

Ans. It is a keyword and a modifier but not an access modifier.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     keyword  modifier


 Q32. Which of the following applies to "private"?

It is a keyword
It is a modifier
It is an access modifier
Core Java2017-04-26 19:57:30

Ans. Yes, all of them applies to private keyword. It is an access modifier.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     keyword  modifier


 Q33. What is a difference between Identifier and keyword ?Core Java2017-04-26 20:01:21

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 :   

   Like      Discuss      Correct / Improve     identifier  keyword


 Q34. Can we use java keywords as identifiers ?Core Java2017-04-26 20:02:06

Ans. No, keyword has pre defined meaning for compiler and hence cannot be used as identifiers.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     keywords  identifier


 Q35. Can we use true and false as identifiers in java ? Are they keywords in Java ?Core Java2017-04-30 09:40:17

Ans. true and false are literals in java. No we cannot use them as identifiers.

  Sample Code for literal

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     identifiers  keywords  literals


 Q36. What is the difference between keywords, identifiers and literals in java ?Core Java2017-04-30 09:45:27

Ans. Keywords are the reserved words that have a pre defined meaning for the compiler and hence are restricted to be used as identifiers.

Identifiers are the name assigned to different programming constructs like classes, interfaces, methods , variables etc.

Literals are the values that are assigned to Identifiers.

For example

int count = 0;

in the above statement "int" is a keyword, "count" is an identifier and "0" is a literal

  Sample Code for keywords

  Sample Code for identifiers

  Sample Code for literals

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     keywords  literals  identifiers


 Q37. Why is goto not used in Java?Core Java2017-05-05 21:43:16

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 :   

   Like      Discuss      Correct / Improve     goto  keywords


 Q38. Which are the reserved words in Java ?Core Java2017-05-31 16:52:35

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 :   

   Like      Discuss      Correct / Improve     java keywords  java reserved words


 Q39. What is the use of final keyword ?Core Java2017-06-08 06:17:54

Ans. final keyword is a modifier that means differently when applied to variables, methods and classes.

1. Final variable cannot be changed once initialized
2. Final method cannot be overridden
3. Final class cannot be sub classed

  Sample Code for final variable

  Sample Code for final method

  Sample Code for final class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     final  final keyword     Trimax IT Infrastructure & Services      Basic        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q40. When we say final x = 10, is the reference final or the value ?Core Java2017-07-29 13:27:04

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 :   

   Like      Discuss      Correct / Improve     final keyword  final variables  references


 Q41. How different is it when final applied to variables and object references ? Core Java2017-07-29 13:31:59

Ans. final when assigned to object references doesn't make them immutable. It means that the references cannot be de-referenced.

final when applied to variables means that the value cannot be changed.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     final keyword  final variable


 Q42. What will be the output of following code ?

public class BuggyBread {

   private int x;

   private BuggyBread(int x){
      x = x;
   };

   public static void main(String[] args){
      BuggyBread buggybread = new BuggyBread(5);
      System.out.println(buggybread.x);
   }
}
Core Java
a. compilation error
b. undefined
c. 0
d. 5

Ans.c. 0

 Q43. The use of volatile keyword facilitates ..Core Java
a. Making Use of Cache for better Performance
b. Avoiding use of Cache
c. Making use of Backward as well as Forward Cache
d. Keeping only one copy of variable in Cache

Ans.b. Avoiding use of Cache

 Q44. Which of following keyword is not allowed for Outer Class ?Core Java
a. public
b. private
c. abstract
d. final

Ans.b. private

 Q45. Which of the following keyword restrict the class from being extended ?Core Java
a. Private
b. Abstract
c. Final
d. Static

Ans.c. Final

 Q46. Which of the following keyword restrict the class from being instantiated ?Core Java
a. Private
b. Abstract
c. Final
d. Static

Ans.b. Abstract



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: