views:

40

answers:

2

Can I pass a value to my own String-like class like this:
MyClass mc = "String";
Is it even possible?

+1  A: 
public class MyClass {

    private String str;

    public MyClass(String str) {
        this.str = str;
    }

    public static void main(String [] args) {
        MyClass mc = new MyClass("This is the string");
    }
}

Make sense?

Scobal
+3  A: 

No this is not possible as Java does not support operator overloading.

haffax