Class
A rectangle divided into compartments is a class in a UML class diagram. The top compartment holds the class's name, the next its attributes, and the one below that its operations.
Easily confused with
How to read it
The class box is the basic shape of a class diagram. The UML 2.5.1 specification draws it as a solid-outline rectangle with the class name centred in bold at the top, and compartments below the name separated by horizontal lines. The attributes compartment comes first and the operations compartment below it. No keyword is written above the name of an ordinary class; other kinds of classifier, such as an interface, carry one in guillemets («interface»). Any compartment can be left out, and the specification says that when one is, nothing can be inferred about what it holds. Robert C. Martin's 1997 tutorial on class diagrams notes that the bottom two compartments are often omitted, and that even when they are shown they seldom list every attribute and operation.
Also searched as: class box, class symbol, uml class, uml class diagram.
What the marks inside the box mean
Each attribute or operation can start with a visibility mark. Course notes at the University of Washington and Virginia Tech's OpenDSA read + as public, - as private, # as protected and ~ as package; the specification lists the same four marks. A slash before an attribute's name marks it as derived: not stored, but computed from other values. A member that is underlined is static. A class name in italics is abstract, and the specification also allows {abstract} written after or below the name.
An attribute is written as name : type, with a Multiplicity in square brackets if it has one, and an operation as name(parameters) : return type, as in +pay() : Boolean.
Three compartments or four
Textbooks teach a box of three compartments: name, attributes and operations (Martin; Kansas State University's CIS 400 textbook). UML 2.5.1 gives a class four mandatory compartments, for attributes, operations, receptions and internal structure, and allows optional ones besides. Since any compartment may be suppressed, a box showing three compartments, two, or only the name is still a class.
Look-alikes
An interface uses the same rectangle with «interface» above its name; a class that implements it is joined to it by a Realization arrow. A box whose name is underlined, or written as name : Class, is an object: one instance of a class, not the class itself. At the top of a sequence diagram, a box with a dashed line hanging from it is a Lifeline. A named rectangle on an entity-relationship diagram is an entity, from a different notation.
Read next
- Next in UML diagram symbolsAssociationA plain solid line between two class boxes is an association: objects of the two classes can have links between them. Labels at either end can name each end's role and say how many objects take part.
- The same shape in Asian flagsFlag of IranIran’s flag has three equal stripes of green, white and red, with the national emblem in red in the centre and the words “Allahu akbar” (“God is greatest”) written 22 times in white along the edges of the green and the red. Iran’s constitution names the colours, the emblem and the motto but gives them no meaning; the art historian Kimia Maleki writes that the 22 marks the day the revolution of 1979 won, the 22nd day of the 11th month of the Iranian calendar.
More UML diagram symbols
The same shape elsewhere
Browse symbols drawn with letters and numbers, lines or squares and rectangles.
Sources
- OMG Unified Modeling Language (OMG UML), Version 2.5.1, OMG document formal/17-12-05, December 2017, Object Management Group, 9.2.4 Notation; 9.4.4; 9.5.4; 9.8.4; 11.4.4
- UML Tutorial: Part 1 -- Class Diagrams, Robert C. Martin, 1997, Northeastern University, Khoury College of Computer Sciences (course reading, CS U370, Fall 2007), Class Diagrams
- UML (CIS 400 Textbook: Object-Oriented Design, Implementation, and Testing), Chapter 5, UML, Kansas State University, Department of Computer Science, Classes; Visibility; Static and Abstract
- UML Class Diagrams (CSE 403 lecture slides), Emina Torlak, CSE 403: Software Engineering, Fall 2016, University of Washington, Paul G. Allen School of Computer Science & Engineering (Internet Archive), Slides 14–16
- The Unified Modeling Language (OpenDSA Complete Catalog, 3.2), Chapter 3, Object-Oriented Programming, OpenDSA Project, Virginia Tech, 3.2.1.2 Class Diagrams
Researched, edited and approved by Rory Hansen before publishing. Last reviewed October 9, 2026. How we research
Added .