Over a million developers have joined DZone.

Java Quiz: Objects and References

DZone's Guide to

Java Quiz: Objects and References

An advanced Java quiz on how objects and object references behave.

· Java Zone ·
Free Resource

Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.

First, let's see how we got the correct answer, F, from last week's quiz:

public void pirnt(){
        for(int i = 0; i < listMySub.size(); i ++ ) {
            if(i == 6) {
                System.out.println("Object6.id=" + listMySub.get(i).id + "    object6.getNumber()=" + listMySub.get(i).getNumber());
            if(i == 8) {
                System.out.println("Object8.id=" + listMySub.get(i).id + "    object8.getNumber()=" + listMySub.get(i).getNumber());
    public static void main(String[] args){
        MyApp ma = new MyApp();

Here's the next quiz, intended for advanced Java developers:


  1. To demonstrate some behaviors and tricks of objects and object references.

What is written to the standard output as a result of executing the following code?

import java.util.ArrayList;
import java.util.List;

public class MyClass {

    List<String> list1 = new ArrayList<String>();
    List<String> list2 = new ArrayList<String>();

    public List<String> method(List<String> list){
        return list;
    public static void main(String[] args){
        MyClass mc1 = new MyClass();
        MyClass mc2 = mc1;
        mc2.list1 = mc2.list2;
        List<String> list3 = mc2.method(mc2.list1);

Let us know your thoughts in the comments, and visit Sar's site here!

Connect any Java based application to your SaaS data.  Over 100+ Java-based data source connectors.

java ,objects ,references ,quiz

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}