-1

I created a class with the name Player. This is the code of the class

classdef Player

     properties
         Name
         Score
     end

     methods
     end

end

Now I use the following code to create an instance of the class. In the final line I attempt to print the value of properties

Player evergreen = new Player();
evergreen.Name = "Roger Federer" ;

evergreen 

An error is thrown up while I run the script. This is the error - Error using Player Too many input arguments.

Error in Team (line 1) Player evergreen = new Player();

Team is the name of the file containing script.

Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
Codacious
  • 1
  • 5

1 Answers1

0

Compared to Java, things in Matlab work a little bit differently. When working with classes, you don't need to specify the type when declaring variables and constructors must be called without the new keyword. While your code run perfectly under Java, in order to make it work under Matlab you have to rewrite it as follows:

p = Player();
p.Name = 'Roger Federer';

For a brief introduction to object oriented programming in Matlab, read this.

Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98