how do i print an object from arrayList

I have created an ArrayList for storing object type data. I want to import data from another class to ArrayList class and print that out. What I want to know is how do I print this object type data. I tried this way but it only shows memory address.

my code :

package com.company;

/**
 * Created by Rakib on 1/12/2018.
 */
public class class2 {
   private int a;
   private int b;
   private String r;


    public void setA(int a) {
        this.a = a;
    }

    public int getB() {
        return b;
    }

    public void setB(int b) {
        this.b = b;
    }

    public String getR() {
        return r;
    }

    public void setR(String r) {
        this.r = r;
    }

    public int getA() {
        return a;
    }
}

main method:

package com.company;

import java.util.ArrayList;

public class Main {

    public static void main(String[] args) {
        // write your code here

        ArrayList<class2> data=new ArrayList();

        class2 obj2=new class2();
        obj2.setA(20);
        obj2.setB(35);
        obj2.setR("rakib");

        data.add(obj2);

        System.out.print(obj2);
    }
}