Composite datatype, is a datatype which is made my combination of more than one primitive datatype.Java
allows to create your own data types using primitive datatypes which are known as composite datatypes.
These datatypes are defined by users ,so it is alsp called as user defined datatype .They include:-
Arrays,list and collection
Combination of primitive data types
Strings
It is different from primitive datatype because they are inbuild datatype defined by java language
specification.They include int,byte,long,short,char,float ,etc.
While composite datatypes are defined by user and made up of primitive datatype values.They include
array,class,interface,etc.
Let us understand this by example:-
Why class is said to be composite datatype
Class is said to be a composite datatype because the methods and variable used are not
predefined,these are user-defined,that is all are defined by user only.User decide which
variables and methods to be added.
In a class,there is a collection of different datatypes,which make the class as a composite datatype.Class
allows composite or user-defined datatypes to be used in a program.
Let us understand this by an example:-
From the above program,we can observe that class named as student,is a composite datatype,as it uses
a collection of two primitive datatype variables- String name and int rollno.So it is made by
collection of primitive datatype.
This student class also has member method as display(),which is user-defined,and class allows
user-defined datatype to be used in a program,so we can clearly say that class is a composite datatype.