Back to the 2026 paper

Module 2: Arrays and Strings

20267m

Write a short note on Constructors and Object Creation.

Worked SolutionAI Assisted

Constructors and object creation

A constructor initializes an object's state. It has the same name as its class and no return type. Constructors may be no-argument, parameterized, or overloaded; if no constructor is declared, Java supplies a default no-argument constructor.

class Book {
    String title;
    Book(String title) { this.title = title; }
}
Book b = new Book("Networks");

new allocates an object, initializes its fields to default values, and invokes the selected constructor. this(...) calls another constructor in the same class and must be first; super(...) calls a superclass constructor and must also be first.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.