Creating and Using Objects

Class is a collection of different types of data elements and their associated behaviors and methods. The keyword ‘new’ is used to allocate space in the memory to store data. The constructor is used to initialise the class object. A constructor in a class is a special type of method called at the creation of an object. It is called a constructor because it constructs the values of data members of the class. They have same name as a class without any access modifier. Parameterised constructor contains arguments to assign a value to the class elements. Objects are the basic run-time entities in an object oriented system. Every object is associated with data and functions that define meaningful operations on that object.

Java provides four types of access specifiers public, private, default and protected. The purpose of access specifiers is to declare which entity cannot be accessed from where.

To Access the full content, Please Purchase

  • Q1

    Why do we need a constructor as a class member?

    Marks:1
    Answer:

    A constructor is a member function with a name same as the class name used to initialise the instance variables of the objects.

    View Answer
  • Q2

    What term is given to empty reference?

    Marks:1
    Answer:

    Empty reference means when the object is only declared but not defined. It is also known as ‘null reference’.

    View Answer
  • Q3

    Which operator is used to create an object?

    Marks:1
    Answer:

    ‘new’ operator is used to create an object.

    View Answer
  • Q4

    Define the term object.

    Marks:1
    Answer:

    Object is an identifiable entity with some characterstics and behaviour.

    View Answer
  • Q5

    What do you mean by a class?

    Marks:1
    Answer:

    A class is often described as a blueprint for an object. It contains both data (referred as attributes) and executable code (referred as methods).

    View Answer