• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the output of this program?  RSS feed

 
Raghu Tiwari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A
{
    void A() /* Line 3 */
    {
        System.out.println("Class A");
    }
    public static void main(String[] args)
    {
        new A();
    }
}
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well...try running it and see what you get!!! That's the best way to be sure.
 
Raghu Tiwari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raghu Tiwari wrote: class A
{
    void A() /* Line 3 */
    {
        System.out.println("Class A");
    }
    public static void main(String[] args)
    {
        new A();
    }
}


It's Showing Nothing!! why?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raghu Tiwari wrote:
It's Showing Nothing!! why?


Hint: what is the difference between a method and a constructor?
 
Ray mann
Ranch Hand
Posts: 48
Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program will print nothing... Is ///line 3 is a method or a constructor .

Why is ///line 3 a method or a constructor?  - hint can constructors have a return type?
When creating a new instance of a class ( new A(); ) do any methods in that class get called?



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!