What is the result?

Given the code fragment:

What is the result?
A. Match 1
B. Match 2
C. No Match
D. A NullPointerException is thrown at runtime.

Download Printable PDF. VALID exam to help you PASS.

3 thoughts on “What is the result?

  1. public static void main(String[] args) {
    StringBuilder sb = new StringBuilder(5); // Int no construtor do StringBuilder defini a largura da string. A mesma é iniciada vazia ou “”.
    String s = “”;

    if(sb.equals(s)) {
    System.out.println(“Match 1”);
    } else if (sb.toString().equals(s.toString())) {
    System.out.println(“Match 2”);
    } else {
    System.out.println(“No Match”);
    }
    }

  2. B
    public static void main(String[] args) {
    StringBuilder sb = new StringBuilder(5);//hier is capacity is 5
    String s=””;
    if(sb.equals(s)){
    System.out.println(“Match 1”);
    }else if(sb.toString().equals(s.toString())){
    System.out.println(“Match 2”);
    }else{
    System.out.println(“No Match”);
    }
    }

    12
    1

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.