Narayana Tutorial

Online Java Tutorial Blog

Classes and Objects interview questions

Classes and Objects interview questions

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.

 

Narayanaswamy

Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development.

I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

The Author

Narayanaswamy

Narayanaswamy

Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development. I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

Leave a Reply

Narayana Tutorial © 2016 Frontier Theme
Show Button
Hide Button