MCQ of JAVA Programming

1. What is an array?
An array is a collection of elements of same data type referred by a common name.The elements are of the array are stored in consecutive memory locations.

2. What are the types of arrays?
One dimensional array, the two-dimensional array, and multidimensional arrays.


3. How to declare a two-dimensional array?
Datatype arrayname[][]=new datatype[ row size][column size]

4. How the individual elements of an array can be accessed?
The individual elements can be accessed using the index. The index of the first element starts with 0.

5. What is Vector?
Vector is just like an array that can store elements of different data types. The elements of the vector can only be objects. So the primitive data type must be converted into object data type before adding to the vector.

6. What is the difference between capacity and size of the Vector?
Capacity specifies the maximum number of objects that can be stored in the vector. Size specifies the number of objects that are present in the Vector.

7. What is the difference between an array and Vector?
The elements of the array are of the same data type. The elements of the Vector can be a different data type. The elements of the array can be of the primary data type. The elements of the Vector can only be objects. The capacity of the array is fixed. The size of Vector can be changed during Runtime.

8. What is a class?
A class is a collection of data and methods that define an object. The variables and methods (functions) of a class are called members of the class.

9. What is an object?
The variable of type class is called object.
Syntax for defining a class
class className
{
//Declaration of instance variables
//Constructors
//Instance Methods
}

10. How can we create objects?
The objects can be created using the new operator. className objectNname=new className();

11. How the members of a class can be accessed?
The members of the class can be accessed using the dot operator
Objectname .variable
Or
Objectname.methodName(Arguments)

12. What is a constructor?
Constructors are special methods whose name is same as the class name. The constructors do not return any value. The constructors are automatically called when an object is created. They are usually used to initialize the member variables.


13. What is a default constructor?
Constructor that does not take any argument is called the default constructor.

14. What is meant by constructor overloading?
Defining more than one constructor for a class which differs in the number of arguments/type of arguments or both is called constructor overloading.

15. What is inheritance?
Inheritance is the process of deriving a new class from an existing class. The newly created class is called subclass and the already existing class is called superclass.

16. What are the types of inheritance?
Single inheritance: One superclass and single subclass.
Multiple inheritances: More than one superclass and single subclass.
Hierarchical inheritance: one superclass and more than one subclass.

Multilevel inheritance: Deriving a subclass from another subclass
Syntax for deriving a subclass
class subclassName extends superclass-name
{
//define the members
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: