The example from the textbook is:

import javax.sounds,midi.*; public class MusicTest{ public void play() { Sequenser sequenser = MidiSistem.getSequenser(); System.out.println("Мы получили синтезатор") } } 

The question is why in the line: Sequenser sequenser = MidiSistem.getSequenser(); the type of the variable is declared as Sequenser , not MidiSistem .

In my mind, the line should look like this:

 MidiSistem sequenser = MidiSistem.getSequenser(); 

Otherwise, some kind of polymorphism is incomprehensible to me.

    3 answers 3

    I will add some generalization to the previous answers. If you have a type T , which has a (static) method getX() , then this does not mean at all that this method will return an instance of type T or even X Need to look at the documentation / source.

      MidiSistem.getSequenser(); is a method that returns a Sequenser object as a result. In my opinion everything is logical.

      • Right and nothing to add - iksuy
      • exactly! beat one minute ahead) - Denis

      When you take the getSequenser(); method getSequenser(); from MidiSistem ( even if literally translated - "get Sequenser" ), then you get the Sequenser object just.

      On the Oracle page , everything is detailed.