Download presentation
Presentation is loading. Please wait.
1
CS230 Tutorial Week 3
2
Agenda Java language review. Inheritance and abstract classes
Interfaces More questions on Assignment 1?
3
Relevant Chapters in Lang-ref
Chapter Lexical Structure 3.10 Literals Chapter Types, Values, and Variables 4.3.3 The Class String Chapter Array Chapter Blocks and Statements
4
Lexical Elements Much easier if you understand compilers!
First step of a compilation process --- tokenization. Which converts source code into lexical elements Identifiers Literals Keywords and operators Comments discarded
5
Literals Integers --- 1, 0x80 Floats --- 0.01 Booleans --- true, false
Characters --- 'a' Strings --- "hello, world" Null --- null
6
Types Value Types (Primitive Types) Reference Types
int, float, Boolean NOT String Has value semantics --- copy value and equality checking Reference Types String Classes and interfaces Has reference semantics --- copy reference, check pointer equality
7
Blocks and Control Statements
Same as C/C++ Differences from python are purely syntactical: Semicolons ; Braces {} Indentation-insensitive
8
Array T[] --- REFERENCE TYPE!
(Very important) semantic difference from C/C++/C# Instantiated with new() Static array --- T[] Dynamic array --- ArrayList<T>
9
Inheritance Not as hard as you might have thought!
“Inheritance” --- in many occasions a loosely-defined concept. Basically means a subclass has inherited states and behaviours from (the/a) superclass. Java --- the superclass --- no multiple inheritance A subclass subtypes (the/a) superclass.
10
However --- in Java The final arbiter of the Java language --- the language reference. In the language reference inheritance has a clear and unambiguous meaning. For details see Section Very detailed rules of what is inherited and what is not. Not all methods are inherited --- no private Specific rules concerning abstract classes and overloading
11
Abstract classes Very simple concept! (Not as hard as you might think.) Any class that has an abstract method. Cannot be instantiated (just like interfaces). To instantiate --- must subclass.
12
Interfaces (Chapter 9 in Langref)
(Conceptually) similar to abstract class --- with (almost) every method abstract Almost --- can have static or default methods Similar to abstract classes --- cannot be instantiated Different to abstract classes --- a subclass can inherit from multiple interfaces (but only one superclass). Java’s middle ground on multiple inheritance --- interfaces only, not from superclasses.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.