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
byte–0
short–0
int–0
long–0
float–0.0
double–0.0
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.
1. private
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
2. public
public members of a class are accessible every where outside the class. so any other program can read them and use them.
3. protected
protected members of a class are accessible outside the class, but generally, within the same directory.
Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in the IT industry for more than 12 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting, Website Development, and IAM(ForgeRock) Specialist
I am a self-learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.