• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

No-args constructor

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I'm goin to sit for the exam next Thursday, I just want to clarify one point from Bill Brogden's cram sheet at point 37.

If your class does not specify a no-arguments constructor, the compiler provides one-if and only if the immediate superclass has no arguments constructor.

As far as i know ... compiler always create no args constructor if we don't specify any constructor, can anyone clarify me about this.
Also other 2 questions:
1. As we know "finally block" is guaranteed to launch, no matter what happen, unless : <code>System.exit()</code> executed. I just want to know is this rule applies to any number inside .exit() method ?
2. Overriding will never allow method to be overriden with a more private access modifier. Which one is more private between protected and default ?
Thanks for any help.
[This message has been edited by roy wiradinata (edited October 29, 2001).]
 
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm goin to sit for the exam next Thursday, I just want to clarify one point from Bill Brogden's cram sheet at point 37.

If your class does not specify a no-arguments constructor, the compiler provides one-if and only if the immediate superclass has no arguments constructor.

As far as i know ... compiler always create no args constructor if we don't specify any constructor, can anyone clarify me about this.

YES YES YES YES
Also other 2 questions:
1. As we know "finally block" is guaranteed to launch, no matter what happen, unless : <code>System.exit()</code> executed. I just want to know is this rule applies to any number inside .exit
() method ?
Yes Yes Yes...

2. Overriding will never allow method to be overriden with a more private access modifier. Which one is more private between protected and default ?
Thanks for any help.
Default Default Default Default...

Good luck on exams!!!
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As to your item my opinion is following:
1.if the class have no other coustructor,then the JVM will give the class a default no-arg constructor .
2.read the list access modifer following:
public --> protected--> no-access modifer --> private.
in the list the later the more private.
 
roy wiradinata
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Taken from book "Java 2 Exam Cram 2nd Ed."
Bill Brogden's cram sheet says in its 37th point :

If your class does not specify a no-arguments constructor, the compiler provides one-if and only if the immediate superclass has no arguments constructor.

As far as i know ... compiler always create no args constructor if we don't specify any constructor, can anyone clarify me about this.


Thanks to Fei Ng and James for the reply, I understand what you mean, I just need to once more clarify the word if and only if quoted above.
[This message has been edited by roy wiradinata (edited October 29, 2001).]
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks to Fei Ng and James for the reply, I understand what you mean, I just need to once more clarify the word if and only if quoted above.


Consider the following example, in this case class Derived has no constructors, but it can not be given a default constructor since its superclass has no default, no argument constructor. This restriction applies because for a subclass, you need to complete constructor hierarchy of the superclasses.

The compiler error you get is -
"No constructor matching Base() found in class Base.
public class Derived extends Base"
Also remember that for a class which does not (explicitly) extend another class, an immediate superclass is Object, which has a default constructor, hence if you have no other constructor in such a class, a default constructor will be provided by Java. So, the statement is right.
HTH,
- Manish

[This message has been edited by Manish Hatwalne (edited October 30, 2001).]
 
roy wiradinata
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Manish.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic