• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can you guess the output without compiling?

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


(Fixed the code after Barry's comments)
[ May 07, 2007: Message edited by: M Krishnan ]
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will give an error because the constructor is private
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shyam,

I think you need to see the var-arg which is allowed since Java 5.0;

1- void method1(String... args) {}
2- void method1(int x,String... arg) {}

Both are legal and compile fine.

In Krishnan's question, the compiler error comes because the constructor is private as already pointed by Ravi.

Thanks,
[ May 06, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by praveen oruganti:
I think it will show error because in the code for abs1() method is declared as private.



abs1() is not a method it is a constructor. This is a bad coding example because it is not using the standard Java convention of using an uppercase letter to start class names and constructors.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it won't compile..you are creating an instance of an abstract class explicitly dude..:-)
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suhaas,
could you please read the Naming Policy and change your name accordingly ? Thank you
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Suhaas UNDEFINED:
it won't compile..you are creating an instance of an abstract class explicitly dude..:-)



Abstract class can't be instantiated. But there is no such case in that code. See what is after new operator. Is it instantiation of the abstract class or abstract class ref variable refers to the object of the subclass?


Polymorphic assignment.


Thanks,
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its throwing this error
"Implicit super constructor Abs1() is not visible for default constructor. Must define an explicit constructor"

which is pefectly fine as per expectation
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic