Classes and Objects interview questions
Table of Contents
We know a class is a model for creating objects. this means the properties and actions of the objects are written in the class. Properties are represented by variables and actions of the objects are represented by methods. So a class contains variables and methods. The same variables and methods are also available in the objects because they are created from the class.
In this post, I am going to sharing important Classes and Objects interview questions.
1) What is hash code?
A) Hash Code is a unique identification number allotted to the objects by the JVM. This hash code number is alos called reference number which is created based on the location of the object in memory, and is unique for all objects, except for string objects.
2) How can you find the hash code of an object?
A) The hashcode() method of Object class in java.lang package is useful to find the hash code of an object.
3) What are the default values of the data types.
A) Data Type Default Value
char — a space
String — null
any class type — null
boolean — false
4) Access Modifiers
A) An access specifier is a key word that specifies how to access the members of a class or a class itself.
We can use access specifiers before a class and its members. There are four access specifiers available in java.
private members of a class are not accessible any where outside the class. They are accessible only whithin the class by the methods of that class
public members of a class are accessible every where outside the class. so any other program can read them and use them.
protected members of a class are accessible outside the class, but generally, within the same directory.