wHAT IS DEFAULT SPECIFIER IN JAVA
wHAT IS DEFAULT CONSTRUCTOR IN JAVA
wHAT IS DEFAULT METHOD IN JAVA
Answers were Sorted based on User's Feedback
Answer / debasankar
DEFAULT SPECIFIER IN JAVA:
There are 4 types of accessibility specifier in java, they
are private,public,protected and default.
There is no key word in java to specify default specifier
When we do not specify any specifier which means default
specifier,
For Example :
public String getName(){...}
// here accessibility specifier is public
String getName(){...}
// here accessibility specifier is defalut, whose scope
is package-scope means this method is not accessible outside
the current package
DEFAULT CONSTRUCTOR IN JAVA:
Default constructor is the implicit constructor provided by
the compiler when we do not specify any constructor in our class
Default constructor looks like..
---------------------------------
<Access Modifier> <class_name>(){
super();// implicit super call
}
I have not heard about any default method in java..As far my
knowledge there is no default method till JAVA platform 1.4....
Is This Answer Correct ? | 20 Yes | 0 No |
Answer / rohit
default specifier specifies access level of class
eg:-
class A{
}
this is default
default constructor is constructor with same name as of
class and no arguments
eg: class A{
A()
}
there is no default method in java
Is This Answer Correct ? | 22 Yes | 5 No |
Answer / safikur
default specifier in java is DEFAULT
which can only be visible within the same package.
You can't access any default member of a class directly
from outside the package , you can access those member
through another method of that class.
default CONSTRUCTOR in java is the constructor which has
the same name of the class and has no arguments. if you
define at least one constructor in a class JVM will not put
the default constructor in the class like..
public className(){super();}
if there is no constructor in the class JVM will put the
default constructor in the class like..
public className(){super();}
since its not visible. but implicitly defined by compiler..
there is no concept of DEFAULT method in java spec.
Is This Answer Correct ? | 5 Yes | 1 No |
Answer / renu
default specifier is-default
default constructor
no default method
Is This Answer Correct ? | 6 Yes | 3 No |
Default Specifier is : friendly. but there is no keyword
provided by java
Default Construtor is : the constructor of top level super
class of each java class that is "Object" class.
Default Method is : main method that would called by
default through the java interpretor.
Is This Answer Correct ? | 5 Yes | 4 No |
Answer / srinu
DEFAULT SPECIFIER IN JAVA:
There are 4 types of accessibility specifier in java, they
are private,public,protected and default.
There is no key word in java to specify default specifier
When we do not specify any specifier which means default
specifier,the default specifier access the with in package
only.
EX:- public void setName(String name)
{
this.name=name;
}
The above method access any class or any package
void setName(String name)
{
this.name=name;
}
The above method can access with in package.
DEFAULT CONSTRUCTOR IN JAVA:-
THE default constructor in java is System default constructor.
EX:-
public class A
{
String name;
public void setName(String name);
{
this.name=name;
}
}
The above program their is no constructor .then that time
java compiler created default constructor.
Note: we can interested see default constructor frist we
compile java program(javac A.java) after javap A.Then that
time u watch system default constructor.
DEFAULT METHOD IN JAVA:--
The dafault method in java is super().
EX:-
public class A
{
A()
{
System.out.println("IAM CONSTRUCTOR FROM CLASS A ");
}
}
public class B extends A
{
B()
{
System.out.println("IAM CONSTRUCTOR FROM CLASS B");
}
public static void main(String k[])
{
B b=new B();
}
}
output:-
IAM CONSTRUCTOR FROM CLASS A
IAM CONSTRUCTOR FROM CLASS B
hence super() method is default method
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / liza
A>Default specifier in java is friendly,but there is no
keyword for it.When we simply write:
class{
........
}
JVM assumes it as having default specifier.Friendly
specifier tells the JVM that this class is accessible to all
the classes but in the same package.
B>Default constructor:it has the same name as that of the
class.It takes no arguments.It is the implicit constructor
and automatically generated in the absence of explicit
constructor.It calls the superclass constructor using super().
C>Default method:There is no default method in java.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vipin dhiman
in java default specifier is public but within the
samepackage.due to this property of public within same
package we have to define public before the main method
bcoz main has to be taken from jdk which is like the
different package. So if we want to anythig accessing to
the diffrent package we have to declare that with the
public keyword explicitly.
default constructor in java is same name of the class whose
object has to be declared.
example
class v
{
public static void main(String vip[])
{
System.out.println("i am vip");
}
in this default constructor is v();
as much as i know ,there is no concept of default method
Is This Answer Correct ? | 1 Yes | 2 No |
Answer / manish kushwaha
1) Default Specifier in Java: there are mainly 4 types of
Specifier in Java
a) public : can be use any where no restriction
b) Protected: can be use in same package and subclass of
different package
c) default : can be use in same package same class and sub
class (you no need to write any key word for that if you
are not writing any word before any method or variable
then compiler and JVM will assume this as default
specifier in java).
d) private : can be use within the class only
2) Default Constructor: Here again two type concept will
come
a) If you are not writing any any constructor then JVM
will assume a default constructor with this constructor
it will call super class constructor as.
class A{
// here if you are not writing any constructor then
JVM will assume default constructor like
A(){
super(); // here it is calling Object class Constructor
}
}
b) if you are writing any constructor then JVM will igore
to assume default constructor it will take your
constructor again here your specifier comes into
picture like
class A{
//you are writing constructor as
A(){
//This is your own constructor with default specifier
you can invoke this constructor within the package.
}
}
3) Default Method: There is no such default method in java
JVM can not Assume a default method.
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / sanjay
DEFAULT SPECIFIER IN JAVA IS CALLED AS PACKAGE ACCESS
DEFAULT SPECIFIER IN JAVA IS CALLED AS CLASS NAME() WHICH
WAS PROVIDED BY COMPILER DURING COMPILATION TIME
THERE IS NO DEFAULT METHOD IN JAVA
Is This Answer Correct ? | 2 Yes | 6 No |
Why sleep()is in Thread and wait() in Object class? Why can't I have both in one class or vice versa?
What is difference between protected and private?
Explain notifyall() method of object class ?
I don’t want my class to be inherited by any other class. What should I do?
how to print the below in java? * * * * * * * * *
What is a protected class in java?
What is singleton class and how can we make a class singleton?
Does constructor return any value?
In which JDK version event-delegation model is introduced?
What does exclamation mean in java?
why is S capital in System.out.println ????
write java code to print second max number in the array