• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

default package?

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


Q4 which of the following is the correct way to define a class that will be in the default package
A1

package default;

import java.util.*;


A2 import java.util.*;

package default;
A3 import java.util.*;
A4

all the above



The answer explanation is given like:
[Even if you don't write "package default" your class will automatically
placed in the "default" package.] What is this "default" package?
I see this irrelevant. "default" is the keyword so, it will yield compilation error.

Please any comment!

Regards,
cmbhatt
[ April 09, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried compiling with package default, but the file did not compile,i guess you cannot give the package name as default with small d.


regards,
Sharan...
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

I think correct option is A3. please compile it i think you will definetly get the answer


Best of luck.

 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
default is a keyword so I don't think that a package default can de defined.

When you don't define a package statement in your class then the default-package will be created.

Also the package statement should be the first statement in your code after declaring the class name.
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think there is a confusion here: about default the concept and default the keyword.

The 'default' keyword applies only in the case of a switch-case construct.

When talking about default packages (and access specifier), default means the 'absence' of any keyword or identifier. So, in common parlance, when you say default package, it means unnamed package. There is no question of using the string 'default' to name it.

cheers.
 
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
Hi Remko,


Originally posted By Remko:
When you don't define a package statement in your class then the default-package will be created.



I dont find any default-package. As you say if you don't define package,
default package will be created. Is your answer influenced by the stated
behavior of different Java IDE's which creates default-package in case not
package statement in your class?

package means what to you? a directory will be created?



-cmbhatt
[ April 09, 2007: Message edited by: Chandra Bhatt ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is certainly a default behavior to place application code.

but a in "default" package.
I do'nt think so.
 
Remko Strating
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the default package I mean there is no package defined. So the compiled class file will be in the same directory.

Stuart Ash has explained everything clear for you.
He has done a good job.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remko is correct. the default package means if there is no package defined, the compiled class file will be in the same directory."

By the way, you can not use package name "default", as "default" is a java reserved keyword.
 
Gaurav Pavan Kumar Jain
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Folks

Ans A3 is correct for Default package
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For a reference on what Stuart described above, see JLS - 7.4.2 Unnamed Packages.
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Remko Strating:
With the default package I mean there is no package defined. So the compiled class file will be in the same directory.

Stuart Ash has explained everything clear for you.
He has done a good job.



Thank you Remko and Patrick for seconding
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic