Write a Java Program to Print object of a class

Java Program to Print object of a clas

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Print object of a clas
Java Program to Print object of a clas

Write a Java Program to Print object of a class

PROGRAM: Java Program to Print object of a class

/*Java Program to Print object of a class*/

class Test {

}

class Main {
public static void main(String[] args) {

// create an object of the Test class
Test obj = new Test();

// print the object
System.out.println(obj);
}
}

IF you want to get output in your way you can use override toString() method

class Test {

@Override
public String toString() {
return “object”;
}
}

class Main {
public static void main(String[] args) {

// create an object of the Test class
Test obj = new Test();

// print the object
System.out.println(obj);
}
}

Leave a Reply

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