Question: I saw a class "AttributeSelectedClassifier" was once created in the following ways:

```
AttributeSelectedClassifier classifier = new AttributeSelectedClassifier();

classifier.setClassifier(base);
classifier.setEvaluator(eval);

```

This above one looks natural to me. But how about the following one.

```
classifier = new AttributeSelectedClassifier();
((AttributeSelectedClassifier)classifier).setClassifier(base);
((AttributeSelectedClassifier)classifier).setEvaluator(eval);

```

I think it should be right, but I am not quite sure about the way of of defining classifier as ((AttributeSelectedClassifier)classifier), how to understand this usage?

Answer: 
This means that the classifier variable is declared as a superclass or superinterface of `AttributeSelectedClassifier`, and that you need to call a method which is not defined in the class or interface, but only on `AttributeSelectedClassifier`. This notation *casts* the variable to `AttributeSelectedClassifier`:

```
Object classifier = new AttributeSelectedClassifier();
// classifier is a AttributeSelectedClassifier, but references as Object
// to call the following method, we need to cast it to AttributeSelectedClassifier
((AttributeSelectedClassifier)classifier).setClassifier(base);
((AttributeSelectedClassifier)classifier).setEvaluator(eval);

```

This is usually the sign of a design problem. Either the methods should be in the superclass or interface, or the variable should be declared as `AttributeSelectedClassifier`.
This:

```
((AttributeSelectedClassifier)classifier)

```

isn't "defining" or "declaring" classifier - it's *casting* it. Presumably in this case `classifier` is declared as some superclass of `AttributeSelectedClassifier`. The code isn't particularly clear though. I'd rewrite the second bit of code (assuming you can't change the declaration of `classifier`) to:

```
AttributeSelectedClassifier temp = new AttributeSelectedClassifier();
temp.setClassifier(base);
temp.setEvaluator(eval);
classifier = temp;

```

That way you get to use all the methods of `AttributeSelectedClassifier` before assigning a value to the less-strongly-typed `classifier` variable.

(I'd probably use a clearer name than `temp`, but we don't have enough context to work out what such a name would be.)