Java 17 Quick Syntax Reference by Mikael Olsson

Java 17 Quick Syntax Reference by Mikael Olsson

Author:Mikael Olsson
Language: eng
Format: epub
ISBN: 9781484273715
Publisher: Apress


// Subclass (child class)

class Apple extends Fruit

{

public String variety;

}

A class in Java may only inherit from one superclass, and if no class is specified, it will implicitly inherit from Object. Therefore, Object is the root class of all classes.// Same as class MyClass {}

class MyClass extends Object {}

Upcasting

Conceptually, a subclass is a specialization of the superclass. This means that Apple is a kind of Fruit, as well as an Object, and can therefore be used anywhere a Fruit or Object is expected. For example, if an instance of Apple is created, it can be upcast to Fruit because the subclass contains everything in the superclass.Apple a = new Apple();

Fruit f = a;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.