Java Interview QA

Q.What Is a Package?
A package is a namespace that organizes a set of related classes and interfaces. Conceptually we can think of packages as being similar to different folders on our computer. We might keep HTML pages in one folder, images in another, and scripts or applications in yet another. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages.
Q. Mention any two attributes required for class declaration.
Ans: Variables and function or state and behaviour.
Q. Differentiate between base and derived class.
The base class is a class whose properties will be inherited and the derived class is a class which inherits the base class. E.g. Of base class is Super and derived class is sub.

(Constructors)

Q. Define Constructor. When a constructor is called?
Ans: A constructor is special member function that is automatically called when an instance of a class is declared.
A constructor is called when an object of the class is created.
Q. Why do we need a constructor as a class member?
Ans: Constructors have one purpose in life: to create an instance of a class.
Q. What is a default constructor? Why is a default constructor called so?
Ans: A default constructor is a special member function that initializes the objects.
It is called because it declares no parameters. It gets invoked without any parameter
Q. What are the characteristics of constructor function?
Ans: Constructors are the special member functions and have the same name as class and it is called automatically when object being create.
Q. What is parameterisedconstructor?
Ans: The constructors which can take different parameters are referred to as Parameterised Constructors.
Q. What is constructor overloading?.

Ans: Defining more than one constructor for a class where they differ in the parameter types or number of parameters passed to the constructor is called overloading.

SHARE THIS
Previous Post
Next Post