Menu

1 / 2

java Interview Questions

DEV Community·PRIYA K·6 months ago
#xSPhnJTd
#beginners#career#interview#java#class
Reading 0:00
15s threshold

1.Difference between class and Object in Java ?

2.What is constructor.How is it different from a method?

It is used to set default or user-defined values for the object's attributes

Primary Purpose

Initializes the state of a new object.

Invocation

Called automatically when an object is created (usually with the new keyword).

Return Type

Does not have a return type, not even void.

Naming

Must have the exact same name as the class.

Inheritance

Is not inherited by subclasses.

Default Version

Provided automatically by the compiler if none are defined.

Key Differences

Feature Constructor Method

Primary Purpose

Initializes the state of a new object.

Defines the behavior or functionality of an existing object.

Invocation

Called automatically when an object is created (usually with the new keyword).

Must be called explicitly by the programmer using the object reference.

Return Type

Does not have a return type, not even void.

Must specify a return type (e.g., int, String, or…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.