

Encapsulation also serves data hiding purpose. Q4) What is data encapsulation and what’s its significance?Īns: Encapsulation is a concept in Object Oriented Programming for combining properties and methods in a single unit.Įncapsulation helps programmers to follow a modular approach for software development as each object has its own set of methods and variables and serves its functions independent of other objects. Q3) What’s the purpose of Static methods and static variables?Īns: When there is a requirement to share a method or a variable between multiple objects of a class instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects. The types of access specifiers for classes are:ġ) Public: Class,Method,Field is accessible from anywhere.Ģ) Protected: Method,Field can be accessed from the same class to which they belong or from the sub-classes, and from the class of same package, but not from outside.ģ) Default: Method,Field,class can be accessed only from the same package and not from outside of it’s native package.Ĥ) Private: Method,Field can be accessed from the same class to which they belong. Q2) What are the various access specifiers for Java classes?Īns: In Java, access specifiers are the keywords used before a class name which defines the access scope. 👉 Free PDF Download: Java Interview Interview Questions & Answers > Sub-class can access all public and protected methods and fields of its super class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class.Ī sub-class is a class which inherits from another class called super class.

Q1) What is the difference between an Inner Class and a Sub-Class?Īns: An Inner class is a class which is nested within another class. Here are Java interview questions and answers for fresher as well as experienced candidates to get their dream job.
