0% found this document useful (0 votes)
3 views4 pages

Class As User Defined Data Type and Constructor

The document provides a comprehensive overview of classes and constructors in Java, detailing their components, types, and features. It explains concepts such as static members, access modifiers, arrays, and various methods related to input and output operations. Additionally, it discusses the differences between constructors and methods, as well as the significance of keywords like 'this' and 'new'.

Uploaded by

tapansaha053
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Class As User Defined Data Type and Constructor

The document provides a comprehensive overview of classes and constructors in Java, detailing their components, types, and features. It explains concepts such as static members, access modifiers, arrays, and various methods related to input and output operations. Additionally, it discusses the differences between constructors and methods, as well as the significance of keywords like 'this' and 'new'.

Uploaded by

tapansaha053
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CLASS AS USER DEFINED DATA TYPE AND CONSTRUCTOR

1. What are the contents of a CLASS?


CLASS contains External wrapper and Internal Wrapper.
External Wrapper – External Wrapper is the class declaration enclosing inner part within a pair of
curly brackets.
Example: class External
{
//inner part of the class
}
Internal Wrapper – Internal Wrapper has three parts namely Instant variable, Constructors and
Member Methods.

2. What is Static Data Member?


A static data member is an instance variable which is global in the class and used commonly by all
the objects of that class type.

3. What is Static Member Method?


A static member method is a member method which uses only static data members or static
instant variables of the objects. Static method can be access directly.

4. Name the Java keyword that:


Indicates that a method has no return type – void
Stores the address of currently calling object – this
Informs that an error has occurred in an I/O operation – throws
Distinguish between Instance and class variable – static

5. What is Constructor?
Constructor is a member method that is written with the same name as class name and is used to
initialize the data members/instance variable. It is invoked at the time of creating any object of
the class.

6. What is constructor overloading?


The process of using a number of constructor with the same name having with different
parameters is known as constructor overloading. If a class contains more than one constructors
then they are automatically overloaded.

7. What is default constructor?


A default constructor initializes the instant variables of an object with definite values/ or default
values as soon as creating object of the class. It is a constructor called by default while creating an
object.

8. What is parameterised constructor?


A parameterised constructor is a member method with same name as class name which is used
to initialize the object variables by passing parametric values at the time of its creation.

9. What is copy constructor?


A constructor that initializes the data members with the initial values copied from another object
is said to be copy constructor.
10. What is the need of constructor?
When we create various objects of a class, the instance variables are automatically allocated
under each object with the same initial values. But in real life we would like to have separate
initial vales for different objects. Further if we have any member method to initialize the instance
variables we may need to call it every time separately after creating an object. So we require such
a member method that can automatically be called while creating an object to initializes its
element. To do so we need a constructor.

11. Write the features of constructor.

⮚ Constructor is defined with the same name as class name.


⮚ Constructor is automatically called/invoked while creating an object.
⮚ Constructor needs no return type.
⮚ Constructor is always public.
⮚ Constructor is only created to initialize the data members and not to be used for other tasks.

12. Write the difference between constructor and method.

CONSTRUCTOR METHOD

a)It has same name as class name. a)It has same or different name as class
name.
b)It is implicitly called. b)It is explicitly called.
c)It does not return any value. c)It may or may not return a value.
d)It is always public. d)It may public, private or protected.

13. What is the function of new keyword?


New operator is used to create a class object or an array. It allocates memory and returns the
reference of memory at run time.

14. What is function of this keyword?


this keyword is used to refer to the current object of the class. It is also used to differentiate
between instance variables and parametric variables.

15. What is private, public and protected access modifiers?


Private – The data members or member methods which are specified as private can be used only
within the scope of a class. These members are not accessed outside the class.

Public – The data members or member methods which are specified as public can be used within
the scope of a class or can be used even outside of the class.

Protected – The data members or member methods which are specified as protected can be used
only within the scope of a class as private members . These members can be used to another
class during inheritance.

16. What is function of import keyword?


Import keyword is used to provide classes stored inside a package in our program. Ex. Import
java.io.*, import java.util.*;
17. What is meant by a package? Give 2 example.
Java application programming interface(API) package is a set of various classes where each class
intern contains different functions for specific operations which we can use to develop our
application program. Two application packages are java.io and java.util, java.awt etc.

18. What is an Array?


An array is a collection of variables having same data type that are referenced by a common
name. Each element of an array can be accessed by specifying its subscript values.

19. What is a Single Dimensional Array?


A S.D.A. is a group of indexed data items of same data type that are referred to by a common
name.

20. Write the advantage and disadvantage of an array.

Advantages of array :-
a) Initialization can be done in a single line statement,
b) Java arrays are dynamic as memory allocation is done at run time.
c) It is possible access any element provided the index is known.
d) A huge number of data can be represented by a single variable name but different index
value.

Disadvantages of array :-
a) Arrays allows us to store only one data type.
b) It always require contiguous free memory location to be allocated for sorting elements.

21. What is use of length variable?


length variable (reference variable) is use to determine the number of elements in an array. It
returns integer value.

22. What do you mean by Linear search/ or Sequential search?


Linear search/ or Sequential search refers to the searching technique in which each element of
an array is compared with the search item, one by one, until the search item is found or all
elements have been compared.

23. What is Bubble sort?


Bubble sort is a sorting process where the largest element is to move the highest index position
in the array. To attain this, two adjacent elements are compared repeatedly and exchanged if
they are not in correct order.

24. “Class is an object factory” explain. Or “Class is a prototype of an object” explain.


Basically a class is an object maker. Each object belonging to a specific class possesses the data
and methods defined within the class. It produces objects of similar type. Hence a class is termed
as object factory/ prototype of an object.

25. Why object is called instance of class?


Object is basically a representative of a class that includes the characteristics and behavior
defined within the class. An object represents the class while using in a program hence it is said
to be instance of a class.

26. Why class in known as composite data type?


Class is a tool to create user defined data type .The class name becomes data type for the
instance used in the program. It is such a data type that includes various predefined data within
it. Hence it is called composite data type.

27. Why class is called user defined data type?


A class can contain data elements as well as the definitions of operations that can be performed
on the class itself. Further, one can use a class as a data type to declare variables. Thus a class can
well said to be a user defined data type.

28. What is stream?


A stream in Java is an ordered sequence of bytes of undetermined length. Streams are ordered
and in sequence so that the Java Virtual Machine can understand and work upon the stream.
There are two types of stream namely Byte stream and Character stream.

29. What is InputStreamReader class?


The InputStreamReader class is a bridge from byte streams to character streams. It reads byte
and decodes then into characters using a specified character set. The character set is the
platforms default character set.

30. What is the function of BufferedReader class?


This class is used to read text from a character input stream, buffering characters so as to provide
for the efficient reading of characters, arrays and lines.

31. What is the function of read()?


The read() function of the BufferedReader class is used to read a character from an input device.
It returns the Unicode of the character being read.

32. What is the function of readLine()?


The readLine() function of the BufferedReader class is use to read an entire line until we press
carriage return key from an input device.

You might also like