Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Jun 19, 2012

    Didn'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 Sharma

    Neeraj Sharma

    @neeraj-iAaNcG Jun 19, 2012

    No 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

    sookie

    @sookie-T06sFW Jun 19, 2012

    #-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 Verma

    Vikash Verma

    @vikash-verma-jF0MOy Jun 19, 2012

    getting 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 Verma

    Vikash Verma

    @vikash-verma-jF0MOy Jun 19, 2012

    I am getting no constructor using javap tool in my, class here goes the output of my class... 😎
    [​IMG]

  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Jun 19, 2012

    your code please...

  • Vikash Verma

    Vikash Verma

    @vikash-verma-jF0MOy Jun 19, 2012

    #-Link-Snipped-# does it always happen that for each and every java program javap tool will display at least one constructor...😎

  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Jun 20, 2012

    Vikash Verma#-Link-Snipped-# does it always happen that for each and every java program javap tool will display at least one constructor...😎

    Sure it will show you all class members using command javap -private <ClassName>
    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\<User>\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[]);
    }
    

    For class super1.

    C:\Documents and Settings\<user>\My Documents\Downloads>javap -private supe
    r1
    Compiled from "HelloWorld.java"
    class super1 extends java.lang.Object{
        super1();
    }
  • Vikash Verma

    Vikash Verma

    @vikash-verma-jF0MOy Jun 21, 2012

    This 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

    sookie

    @sookie-T06sFW Jun 21, 2012

    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[]);
    }

    And can you Please tell what is your code? B.java?

  • sookie

    sookie

    @sookie-T06sFW Jun 21, 2012

    I 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 Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Jun 21, 2012

    my JDK giving error while running javap B.
    While "javap -private B". is working fine.
    #-Link-Snipped-# , can you confirm this.

  • sookie

    sookie

    @sookie-T06sFW Jun 21, 2012

    ianoopmy JDK giving error while running javap B.
    While "javap -private B". is working fine.
    #-Link-Snipped-# , can you confirm this.

    show me the error and your B.java ?

  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Jun 21, 2012

    sookieshow me the error and your B.java ?

    😲, its working, what's wrong , I was doing

    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\<user>\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\<user>\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\<user>\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

    sookie

    @sookie-T06sFW Jun 21, 2012

    ianoop😲, its working, what's wrong , I was doing

    Cool...πŸ˜€

  • Vikash Verma

    Vikash Verma

    @vikash-verma-jF0MOy Jun 24, 2012

    #-Link-Snipped-# you are right...😎