As far as I know, new keyword is used to instantiate classes. And I think we need to call the class constructor and pass its arguments after this keyword. Right?
Okay, Here is a code snippet:
public class JavaApp{
public static void main(String[] args) {
String st1 = "Test";
String st2 = new String("Test");
byte[] b1 = {'a', 'b'};
byte[] b2 = new byte[]{'a', 'b'};
byte[] b3 = new byte[]('a','b'); //Error
byte b4 = 3;
byte b5 = new byte{3}; //Error
byte b6 = new byte(3); //Error
}
}
My questions:
- What's the difference between
st1andst2? - Why we must pass the arguments of constructor in
{}instead of(), in theb2declaration line? - Why I receive error for
b5andb6?
