SLK Group interview question

String s = new String() ; byte [] b= s.getBytes(); Is this code right? Will it compile /run?

Interview Answer

Anonymous

Dec 18, 2018

I told if you want some values in this array there should be some value in string as it will have empty elements. Her reply was this is an error. There should be some value in the string constructor and even getBytes() method need some parameters such as offset and all. Now it was a clear indication that either she is wrong or java is. As the statement was syntactically correct and it will get compiled and executed. As both are possible I. E string() as well as getBytes(). Now one can understand how horrible that interview was