Home / Questions / Can you refer to a class as a composite type / user-defined type?
Explanatory Question

Can you refer to a class as a composite type / user-defined type?

👁 50 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

✅ Yes.

  • A class is composite because it groups together multiple variables (fields) and methods.

  • A class is also a user-defined type because it is defined by the programmer (not provided as a built-in primitive).

Example:


class Book {
    String title;    // field
    String author;   // field
    int pages;       // field
}

Book is both:

  • A composite type (made up of String and int)

  • A user-defined type (created by the programmer).