Java OCA OCP Practice Question 1141

Question

Which of the following are valid at line 1?

public class Main { 
    //line  1: insert code here. 
} 

Select 2 options

  • A. String s;
  • B. String s = 'myValue';
  • C. String s = 'a';
  • D. String s = this.toString();
  • E. String s = myValue;


Correct Options are  : A D

Note

A string must be enclosed in double quotes ".

'a' is a char. "a" is a String.

Every class directly or indirectly extends Object class and Object class has a toString() method.

The toString() method will be invoked.

The String that it returns will be assigned to s.

There is no variable myValue defined in the given class.




PreviousNext

Related