• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Doubt regarding Default costructor

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
Help me out!!

given:
public class Test{}

What is the prototype of the default constructor
A.Test()
B.public Test()
The answer is given as Test();
but I think it's public Test();Can you people tell me which one is correct..
Regards
koushik
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai buddy,
As far as i know "default constructors will have the same accesiblity as that of its class".UR class is public ,so default constructor must have public access specifier.
hope it helps
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


If the class is declared public, then the default constructor is implicitly given the access modifier public ; if the class is declared protected, then the default constructor is implicitly given the access modifier protected ; if the class is declared private, then the default constructor is implicitly given the access modifier private ; otherwise, the default constructor has the default access implied by no access modifier.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Naturally the default constructor must have no parameters.

The most obvious default is to have no scope specifier, but you could define the constructor as public or protected.

Constructors cannot be native, abstract, static, synchronized or final.


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

if the class is declared protected, then the default constructor is implicitly given the access modifier protected ; if the class is declared private, then the default constructor is implicitly given the access modifier private ;



==========================================
A top level class can never be protected & private ...so be careful before your comments...
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic