How can this statement be true? I mean how can I implement it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can this statement be true? I mean how can I implement it?

In my book it is written that when the main method is not included the execution of the class program can be done through creating objects?

26th Nov 2021, 5:15 PM
Atul
3 Answers
+ 4
Imagine you have a class Dog: public class Dog{ public void bark(){ System.out.println("woof"); } } This class itself does nothing. But in your class with the main method you can do this: Dog myDog = new Dog(); myDog.bark();
26th Nov 2021, 5:25 PM
Denise Roßberg
Denise Roßberg - avatar
0
Yes that is what I am saying it will show no output. That means the statement written in the book is wrong?
27th Nov 2021, 5:58 AM
Atul
0
Atul I am not sure what you have tried but my example works as expected: https://code.sololearn.com/cTKVhrJttHVl/?ref=app
27th Nov 2021, 7:16 AM
Denise Roßberg
Denise Roßberg - avatar