Top Advanced Java Interview Questions and Answers

    11 Votes

31) Why String is immutable in Java ?

String is a special type of immutable class. Immutable class is a class which once created, it’s contents can not be changed. Immutable objects are the objects whose state can't be changed once constructed.


32) Can you explain about information hiding in Java ?


Information hiding helps objects to hide critical information from other other objects accessing it. It effectively decouples the method being invoked from the internal workings of a function. By doing so, object can change the hidden portions of the function without changing the calling code. Encapsulation is a common technique programmers use to implement information hiding.


33) Can you explain about encapsulation in Java ?


Encapsulation helps java to bind code and data it manipulates, restrict outside interference and misuse of data. It also hides irrelevant details of an object.


34) Can you explain about the access modifier in Java ?


Access modifiers specifies the access levels of a variable or method. Java access modifiers are public, private, protected, default modifier (Default access modifier).

Access ModifiersSame ClassSame PackageSubclassOther packages
public Yes Yes Yes Yes
protected Yes Yes Yes No
default Yes Yes No No
private Yes No No No


35) What is the difference between super() and this() in Java ?

If you want to access methods of the base class from derived class "super" keyword is used. To access methods of the same class "this" keyword is used.


36) Can you explain about the constructor in Java ?

  • Java constructors are special methods that are called when an object is instantiated. 
  • When objects are instantiated, arguments passed to the constructor will initialized the variables in an object. 
  • Name of the constructor should be same as the name of the Class. It can't have any return type.
  • A class can have multiple constructors. Calling a constructor from another constructor in the same class is called Constructor chaining. 
  • All classes have a default empty constructor.


37) Can constructor take parameters ?


Yes. Constructor can take arguments.


38) Can you explain about the default constructor in Java ?


When a constructor is not specified explicitly, java compiler automatically creates a "Default Constructor". When we creates and object instance, default constructor initialize variables with it's default values. 


39) What are the common reasons to define a default constructor ?

  • To construct an object with default values. 
  • To initialize an object that doesn't need parameters in that initialization process. 
  • To redefine the scope of the constructor. By making the default constructor private, Java prevents everyone other than the class from constructing an object.


40) Can you explain about native method in Java ?

  • Native is non access modifier. It can be applied only to method. 
  • It indicates the Platform-Dependent implementation of method or code.
Page 4 of 6

Popular Videos

communication

How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

Java OOPS Interview Questions and Answers
Java Interview Questions
Java Collections Interview Questions and Answers
Java Thread Interview Questions and Answers