HomeJava

Java – Interview Questions and Answers – Part 4

Java – Interview Questions and Answers – Part 4

1) What are the differences between methods and constructors?

Answer: The below is the answer for this question:

When compared to Methods:

1. Constructors won’t have any return type

2. Constructors should have the same as the Class name

3. Constructors are automatically called when objects are created

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


2) Can Constructors be overloaded?

Answer: The below is the answer for this question:

Yes, we can overload Constructors.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


3) Can  we override constructors?

Answer: The below is the answer for this question:

No, we cannot override the Constructors, due to below:

As Constructors should have the same name as the Class name, constructor name in child class will be different from its parent class.

And hence, it won’t be possible to override any Constructor.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


4) What is the purpose of using this keyword?

Answer: The below is the answer for this question:

The purpose of using this keyword is to differentiate the instance variables from parameterized variables of constructors and methods.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


5) What is the purpose of packages?

Answer: The below is the answer for this question:

The purpose of packages is to group related classes, interfaces and other files in a Java Project.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


6) What is a Class?

Answer: The below is the answer for this question:

Class is a template or blueprint for creating objects of similar kind.

Class defines the common variables and methods to be used by the objects created from the Class.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


7) What is an Object?

Answer: The below is the answer for this question:

Object is a real world entity having some state and behavior.

Object is an Instance of a Class.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


8) What is the difference between local and global variables?

Answer: The below is the answer for this question:

Variables created inside the methods are known as Local Variables.

Where as Variables, which are directly created inside the Class, but outside the methods are known as Global Variables.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


9) Can we access instance variables inside static methods?

Answer: The below is the answer for this question:

No, we cannot access instance variables inside the static methods.

As static methods can only access static stuff.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


10) Is Java 100% Object Oriented Programming language?

Answer: The below is the answer for this question:

No, Java is not an 100% Object Oriented Programming language

Primitive Data types in Java are not Object Oriented

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


Please leave your questions/comments/feedback below.

Happy Learning 🙂

Arun Motoori ( www.QAFox.com )

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp