M
M
MickeyMouzze2016-08-06 13:09:58
PHP
MickeyMouzze, 2016-08-06 13:09:58

Are types derived from classes?

How are types formed? Explain, please

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
krypt3r, 2016-04-05
@muldy

Something like this
This is if the position of the characters A and C does not matter. In general, you can get by with strpos () - regular expressions work slower

R
Rou1997, 2016-08-06
@Rou1997

A class is one of the varieties of a type; in addition to classes, there are structures, interfaces, and base types, such as int.
In Java and most languages ​​it will give a compilation error, in some (interpreted) languages ​​it will give a runtime error, or the IDE will indicate an error.

D
Dmitry Vapelnik, 2016-08-06
@dvapelnik

no, Java is not supposed to collect this and should say that the `Person` class was not found,
looked for a description in the book, but did not find it. I will describe myself. there's a deeper question here,
you're right - you have a type on the left, and you use a class on the right. in the case of a class that does not inherit from anything and does not inherit anything from it, this is the class.
Let's further imagine that you have two classes Person and Worker. while Worker is inherited from Person. you can safely write the following:

Person personFoo = new Person();
Person personBar = new Worker();
Worker workerBeez = new Worker();

everything is clear with the first and third lines, and the second line, as you understand, is due to polymorphism. personFoo and personBar objects will be of the same type: Person. all these three objects will formally belong to the same type and workerBeez can be used in the same place as Person if the principle of substitution
is followed, a similar situation with interfaces. if a class implements an interface, then the objects of this class will also refer to the type of the interface:
now if all this is put together, then a class that inherits from another class and implements several interfaces, in fact, belongs to several types: the type that belongs to the class from which it is inherited, the types of all interfaces and its own type

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question