is it possible for a class in java to have no constucror...
I am finding no constructor while using javap tool for my java class...
Replies
-
Anoop KumarDidn't used javap command..
but default constructor always added to class file, either it written in source code or not. did you tried for it JD java decompiler to generate source file from class file.
If you have any doubt just call super(); as first line in subclass *constructor without having any constructor in super class. see what will happen!!!!๐ -
Neeraj SharmaNo need at all. There is always a default constructor as follows even if you dont declare yours,
It has following structure.
public class_name
{
} -
sookie#-Link-Snipped-# I am getting the default constructor getting displayed for my java class using javap. Can you please share your java class along with javap command results?
-
Vikash Vermagetting following error while using super(); in subclass constructor...๐
C:\Users\VIK\Desktop>javac *.java
B.java:6: cannot find symbol
symbol : constructor A()
location: class A
super();
^
1 error -
Vikash VermaI am getting no constructor using javap tool in my, class here goes the output of my class... ๐
-
Anoop Kumaryour code please...
-
Vikash Verma#-Link-Snipped-# does it always happen that for each and every java program javap tool will display at least one constructor...๐
-
Anoop Kumar
Sure it will show you all class members using command javap -privateVikash Verma#-Link-Snipped-# does it always happen that for each and every java program javap tool will display at least one constructor...๐
If your code is like this one
class super1{ } public class HelloWorld extends super1{ HelloWorld (String s) { s="ABC" ; } public static void main(String[] args) { System.out.println("Hello, World"); } }
Then compile the code and use javap you will get following output
C:\Documents and Settings\
For class super1.\My Documents\Downloads>javap -private Hell oWorld Compiled from "HelloWorld.java" public class HelloWorld extends super1{ HelloWorld(java.lang.String); public static void main(java.lang.String[]); }
C:\Documents and Settings\
\My Documents\Downloads>javap -private supe r1 Compiled from "HelloWorld.java" class super1 extends java.lang.Object{ super1(); } -
Vikash VermaThis is what my code is displaying...๐
C:\Users\VIK\Desktop>javac B.java
C:\Users\VIK\Desktop>javap B
Compiled from "B.java"
class B extends java.lang.Object{
public static void main(java.lang.String[]);
} -
sookie
And can you Please tell what is your code? B.java?Vikash VermaThis is what my code is displaying...๐
C:\Users\VIK\Desktop>javac B.java
C:\Users\VIK\Desktop>javap B
Compiled from "B.java"
class B extends java.lang.Object{
public static void main(java.lang.String[]);
} -
sookieI was just trying something and came to know that may be your B.java has declared constructor as "private" If you have its visibility as "private" then following command "javap B" will not show the private constructor. In order to view it you will have t explicitly run the command as "javap -private B".
-
Anoop Kumarmy JDK giving error while running javap B.
While "javap -private B". is working fine.
#-Link-Snipped-# , can you confirm this. -
sookie
show me the error and your B.java ?ianoopmy JDK giving error while running javap B.
While "javap -private B". is working fine.
#-Link-Snipped-# , can you confirm this. -
Anoop Kumar
๐ฒ, its working, what's wrong , I was doingsookieshow me the error and your B.java ?
Here is final conclusion
With public constructor Source: public class abc{ abc(){} public static void main(String[] args) { System.out.println("Hello, World"); } } Output C:\Documents and Settings\
\My Documents\Downloads>javap abc Compiled from "abc.java" public class abc extends java.lang.Object{ public abc(); public static void main(java.lang.String[]); } With private constructor Source: public class abc{ private abc(){} public static void main(String[] args) { System.out.println("Hello, World"); } } Output C:\Documents and Settings\ \My Documents\Downloads>javap abc Compiled from "abc.java" public class abc extends java.lang.Object{ public static void main(java.lang.String[]); } With private constructor C:\Documents and Settings\ \My Documents\Downloads>javap -private abc Compiled from "abc.java" public class abc extends java.lang.Object{ private abc(); public static void main(java.lang.String[]); } -
sookie
Cool...๐ianoop๐ฒ, its working, what's wrong , I was doing -
Vikash Verma#-Link-Snipped-# you are right...๐
You are reading an archived discussion.
Related Posts
BMW's Vision Efficient Dynamics concept is getting closer to reality with the unveiling of third car in the series of i8 series. It houses a hybrid engine with Brake Energy...
Could you please suggest some cities to take GRE test where the paper will be somewhat easy..
someone plz tell me why does d center tapping of transformer gives 180 degree phase shift at 2 sides of secondary?
hey guys ๐
thnx 2 admin 4 this group โโ
๐๐๐๐๐๐๐โ๐