nerdexam
Oracle

1Z0-811 · Question #11

Given: public class Student { string sName; char grade; public static void main (String[] args) { Student s = new Student (); System.out.println ("\"" + s.sName + ":" + s.grade + "\""); } } What is…

The correct answer is A. [null:]. Option A is correct because Java initializes instance variables to their type defaults: sName is a String (reference type), so it defaults to null, which when concatenated in a String expression prints literally as null; grade is a char (primitive type), so it defaults to…

Java Basics

Question

Given: public class Student { string sName; char grade; public static void main (String[] args) { Student s = new Student (); System.out.println (""" + s.sName + ":" + s.grade + """); } } What is the result?

Options

  • A[null:]
  • B[:]
  • C[null:null]
  • D[null]

How the community answered

(16 responses)
  • A
    88% (14)
  • B
    6% (1)
  • D
    6% (1)

Explanation

Option A is correct because Java initializes instance variables to their type defaults: sName is a String (reference type), so it defaults to null, which when concatenated in a String expression prints literally as null; grade is a char (primitive type), so it defaults to '\u0000' (the null character), which renders as an invisible/empty character in output - producing "null:" (the brackets in the choices represent the printed double-quotes from "\").

Option B is wrong because it implies sName printed as empty, but a null String reference always concatenates as the text "null", not as an empty string. Option C is wrong because it assumes grade also prints as null, but that only happens with reference types - primitives like char have a numeric zero-equivalent default ('\u0000'), not null. Option D is wrong because it's missing the colon separator and omits the char value entirely.

Memory tip: Think "reference types get null, primitives get zero" - for char, zero means '\u0000' (invisible), not the word "null", so only the String side of : produces visible output.

Topics

#default values#instance variables#char type#string concatenation

Community Discussion

No community discussion yet for this question.

Full 1Z0-811 Practice