100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CE203 revision notes from lecture 3 onwards () £2.99   Add to cart

Lecture notes

CE203 revision notes from lecture 3 onwards ()

 162 views  2 purchases

Complete lecture notes from the CE203 module, application programming from the 3rd lecture onwards, language covered in lectures is Java. Topics range from Inheritance, collections framework, swing, classes, and more

Last document update: 7 year ago

Preview 1 out of 17  pages

  • August 1, 2017
  • August 1, 2017
  • 17
  • 2016/2017
  • Lecture notes
  • Unknown
  • 3-9
All documents for this subject (1)
avatar-seller
jacksmith1
CE203 revision Lecture 3 onwards

Inheritance

To invoke the constructor from the superclass within the subclass constructor, you have to use the
‘super’ command which must be the first statement in the constructor

If the statement does not exist then a no-argument error will occur

A superclass may refer to an object of the subclass

To access subclass method for a variable declaration, you must use downcasting, this tells the
compiler that the variable will refer to a subclass object

This can be done like

Int r = ((subclass)subclassObect).method();

The odd parentheses order is necessary since method application has a higher precedence than
downcasting, without them the downcast would be applied to the result of just the method name

If the subclass object variable didn’t refer to the subclass, an exception called ClassCastException will
be thrown.

Subclass objects can be stored in an array of superclass objects

If you wish to find all the subclass objects in an array of both the superclass and sub class, you should
use ‘instanceof’. Example below:



For (int i = 0; I < a.length; i++)

If(a[i] instanceof subclass)

System.out.println(a[i]);



To copy the contents of one array into another, you can use a method which takes both the arrays as
Object[] arguments, throws ArrayStoreException if the destination array is shorter than the source,
and then iterates through the items of the source array and dest[i] = source[i]

The method only works if the element types of both arrays’ arguments are the same, for example
both int.

And if the source array type is a subclass of the destination array type

Abstract classes:

An abstract class is a class that cannot be instantiated, only inherited from.

All inheriting classes can use methods from the abstract class

Abstract classes provide more a framework that allows subclasses to be interchanged with other
inheriting subclasses, similar to headers in C++.

Interfaces:

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller jacksmith1. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for £2.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

60904 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy revision notes and other study material for 14 years now

Start selling
£2.99  2x  sold
  • (0)
  Add to cart