The film depicts the lives and misadventures of two unemployed young actors in late-1969 London. They are the flamboyant alcoholic Withnail and "I" (named "Marwood" in the published screenplay but not in the credits) as his relatively more level-headed friend and the film's narrator. Withnail comes from a privileged background and sets the tone for the friendship. They live in a filthy Georgian flat in Camden Town. Their only company at the flat is the local drug dealer, Danny.
The roommates squabble about housekeeping and leave to take a walk. In Regent's Park, they discuss the state of their acting careers and a possible country vacation, settling on a visit to Withnail's uncle Monty, who has a cottage near Penrith. After a near fight with a large and belligerent Irishman, they return home to prepare for their trip. They visit Monty that evening at his luxurious Chelsea house. Monty is a melodramatic aesthete and Marwood realizes he is homosexual. The three briefly drink together as Withnail casually lies to Monty about his acting career and lies that Marwood went to Eton. Before leaving, Withnail arranges to borrow the cottage.
The countryside is beautiful, but the weather is cold and often inclement, the cottage is without running water or light, they have no food and the locals are unwelcoming â in particular a poacher, Jake, whom Withnail offends. They see Jake prowling around their cottage. Marwood suggests they leave for London the next day. Withnail in turn demands that they share a bed in the interest of safety, but Marwood refuses. During the night, Withnail becomes paranoid that the poacher is going to come after them and climbs under the covers with Marwood, who angrily leaves for a different bed. Hearing the sounds of an intruder breaking into the cottage, Withnail again joins Marwood in bed. The intruder turns out to be Monty, who has been stranded with a punctured tyre.
Monty has brought supplies and persistently comes on to Marwood. He offers to take them into town to get fitted into rubber boots, but they end up spending the money he gave them on drinks. Monty is hurt, though he puts it out of his mind quickly during a boozy round of poker. Marwood is terrified of what else Monty might try on him and wants to leave immediately. After much argument, Withnail insists on staying. Late in the night, Marwood keeps trying to evade Monty but he eventually corners him in the guest bedroom. Monty reveals that Withnail, when arranging to borrow the cottage, had told Monty that Marwood was a closeted homosexual and that he himself had rejected Marwood's advances. Marwood claims that Withnail is the closeted one and that the two of them have been in a committed relationship for years. He claims that Withnail is only rejecting him because Monty is around, and that this is the first night that they haven't slept together in years. Monty, a romantic, accepts this explanation and apologizes for coming between them. In private, Marwood furiously confronts Withnail and insists that he will pay.
The next morning, Marwood finds that Monty has left for London, leaving note of apology wishing them happiness together. They continue to argue about their behaviour and Monty. When Marwood receives a telegram about a callback from an earlier audition, he insists they return to London.
As Marwood sleeps, Withnail drunkenly speeds and swerves until pulled over by the police. Withnail is arrested for driving under the influence, and tries to falsify his urine sample. The pair return to the flat to find Danny and a stranger named Presuming Ed squatting there. Marwood calls his agent and discovers that he is wanted for the lead part in a play. The three, and Presuming Ed, get high smoking a huge cannabis joint. The celebration ends when Marwood learns they have received an eviction notice for unpaid rent, while Withnail is too high to care.
Marwood prepares to leave for the station, turning down Withnail's request for one last drink. In Regent's Park in the rain, Marwood confesses that he will miss Withnail, but does not allow him to accompany him further to the station. Bottle of wine in hand, Withnail declaims "What a piece of work is a man!" from Hamlet to an uncomprehending pack of wolves behind a fence in the London Zoo. The camera watches as he turns and walks away into the gloomy distance, swinging the bottle, as the credits start to roll.

Question: What play does Withnail quote at the end?
Answer: He quotes Hamlet.