0

so I'm having a lot of trouble understanding how this works...

public class Arbitros_modelo {

public Arbitros_modelo(String nombre, String nacionalidad, String posicion) {


    // where my  idea   is to create objects with Constructor(String nombre)
            // eg Arbitros_modelo(esteban, colombiano, lateral)

         Object[]  nombre = {nacionalidad, posicion};

}

but this gave me error,this is the idea, but it does not work probbly not understanding the concept so can someone explain to me o give me an article where i can learn this ?... so did some researching and found this:

public class Arbitros_modelo {


public Arbitros_modelo(String nombre, String nacionalidad, String posicion) {


Object[] Arbitros_modelo.class.getConstructor(Arbitro_modelo.class).newInstance(nombre) = {nacionalidad, posicion}  

}

I know this is VERY wrong but just can't understand how to implement this correctly, please help. thanks !

1
  • you can have global String variables in your class and set them in your constructor Commented Apr 16, 2014 at 13:40

4 Answers 4

1

You can do it like this.

public class Arbitros_modelo { 
private String nombre;
private String nacionalidad;
private String posicion;

public Arbitros_modelo(String nombre, String nacionalidad, String posicion) {
       this.nombre=nombre;
       this.nacionalidad=nacionalidad;
       this.posicion=posicion;
}

Simple

Sign up to request clarification or add additional context in comments.

Comments

0

You are mistaking some parts of OOP. You must first implement a class which should be able to contain Your data (Person for example) which should have fields (nombre, nacionalidad and position).

Then You probably would like to create a Person object with given parameters using constructors.

The Object phrase is not a phrase for class definition. It is a global java class from which all other classes extend.

Still I believe some more information about what You would actually like to do here is necessary.

What is more try revising: http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html and http://www.javaworld.com/article/2076204/core-java/understanding-constructors.html

Comments

0

You are using the same variable name twice, first time as constructor argument:

public Arbitros_modelo(String nombre, String nacionalidad, String posicion) {

Second time as local variable:

Object[]  nombre = {nacionalidad, posicion};

Just rename it in one of these places and you should be fine.

Comments

0

If I understand what you're trying to do, then you can use this with a constructor,

public Arbitros_modelo(String nombre) {
  super(); // <-- be explicit
  System.out.println("Constructor one");
  this.nombre = nombre;
}
public Arbitros_modelo(String nombre, String nacionalidad, String posicion) {
  // Object[] Arbitros_modelo.class.getConstructor(Arbitro_modelo.class).
  // newInstance(nombre) = {nacionalidad, posicion}  
  this(nombre);
  System.out.println("Constructor two");
  this.nacionalidad = nacionalidad;
  this.posicion = posicion;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.