Class as a User Defined Types

Class as a User Defined Types

[ICSE Syllabus on this Topic “Class as a User Defined Types”]
Class as a composite type, distinction between primitive type and composite of class type.

Q. What is data type?
Ans: Data types are means to identify the type of data and associated operations of handling it.

Q. What is composite (user define) data type? Explain with an example?
Ans: A composite datatype is that datatype that are based on fundamental or primitive datatypes. A ‘class’ is an example of composite datatypes.
class Date
int dd, mm, yy;
public Date()

Q. What is user define datatype?
Ans: A user defined datatype is a data type that is not a part of the language and is created by a programmer.

Q. Can you refer to a class as a user defined (composite) data type?
Ans: Yes, we can refer to a class not having a main() method as user-defined data type.

Q. What is the difference between primitive data types and composite data types?
Ans: (i) primitive data types are built-in data types. Java provides these data types. User-defined data types are created by users. (ii) The size of primitive data types are fixed. The size of user-defined data types are variable. (iii) Primitive data types are available in all parts of Java programs. The availability of user-defined data types depends upon their scope.

Q. Compare a class as a user defined data type and class as an application?
Ans: In Java, all functionality is enclosed in classes. But in order for a class to be user-defined data type, it should be act different from that of an application. i.e. it should not include main() method in it. Although we can create instance of classes containing main method, they should not be referred to as used-defined data type. Such classes (containing main() method) are more analogues to application than a data type.

Q. How are private member different from public member of a class.
Ans: Private members of a class are accessible in the member function of the class only, where as public members are accessible globally.

Q. How are protected members different from public and private members of a class.
Ans: Protected members of a class are accessible in all the classes in the same package and subclass in the other packages. private members of a class accessible in the member functions in the class only. Where as public members are accessible globally.

Q. Mention any two attributes required for class declaration.
Ans: The two attributes for class declaration are: 1. Access Specifier  2. Modifier 3. Class Name

Leave a Comment