Java Programming and Technical Programming Basics

public String makingStrings()
{
String str = "Welcome";

str = str.substring(1, 5);

str = str.toUpperCase();

return str;
}

How many String objects are created in the heap when this method is invoked?

A. 4
B. 2
C. 3
D. 1

Read Solution (Total 1)

Java Other Question

Given a method in a public class, ________ access modifier must be used to restrict access to that method to only the other members of the same class.

A. final
B. private
C. protected
D. default
What is the output of the following program?

import java.util.Arrays;

class Test
{
public static void main(String args[])
{
String[] cities = new String[]{"London", "Paris", "NewYork", "HongKong", "Tokyo"};
String[] metros = new String[]{"London", "Paris", "NewYork", "HongKong", "Tokyo"};
String[] capitals = cities;
System.out.println("cities == metros : " + (cities == metros));
System.out.println("cities == capitals : " + (cities == capitals));
System.out.println("cities.equals(metros) : " + cities.equals(metros));
System.out.println("cities.equals(capitals) : " + cities.equals(capitals));
System.out.println("Arrays.equals(cities, metros) : " + Arrays.equals(cities, metros));
System.out.println("Arrays.equals(cities, capitals) : " + Arrays.equals(cities, capitals));
}
}


A. cities == metros : false
cities == capitals : true
cities.equals(metros) : true
cities.equals(capitals) : true
Arrays.equals(cities, metros) : false
Arrays.equals(cities, capitals) : true

B. cities == metros : false
cities == capitals : true
cities.equals(metros) : true
cities.equals(capitals) : true
Arrays.equals(cities, metros) : true
Arrays.equals(cities, capitals) : true

C. cities == metros : false
cities == capitals : true
cities.equals(metros) : false
cities.equals(capitals) : true
Arrays.equals(cities, metros) : true
Arrays.equals(cities, capitals) : true

D. cities == metros : false
cities == capitals : true
cities.equals(metros) : false
cities.equals(capitals) : true
Arrays.equals(cities, metros) : true
Arrays.equals(cities, capitals) : false