2.4.10

Objects

Test yourself

Objects

Objects are made from classes.

Illustrative background for Creating an ObjectIllustrative background for Creating an Object ?? "content

Creating an Object

  • Objects are created from classes.
  • To create an object we use the keyword new and the name of the class:
    • MyClass myObj = new MyClass();
Illustrative background for Accessing attributesIllustrative background for Accessing attributes ?? "content

Accessing attributes

  • If an attribute of an object is public, then it can be accessed from outside the class.
  • Object attributes are accessed using dot notation:
    • int attr = myObj.attr;
Illustrative background for Calling methodsIllustrative background for Calling methods ?? "content

Calling methods

  • If a method of an object is public, then it can be accessed from outside the class.
  • Object methods are accessed using dot notation:
    • myObj.doSomething();

Jump to other topics

1Components of a Computer

2Software & Software Development

3Exchanging Data

4Data Types, Data Structures & Algorithms

5Legal, Moral, Cultural & Ethical Issues

6Elements of Computational Thinking

6.1Thinking Abstractly

6.2Thinking Ahead

6.3Thinking Procedurally

6.4Thinking Logically

6.5Thinking Concurrently

7Problem Solving & Programming

8Algorithms

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium