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 Kumar
    Anoop Kumar
    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
    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
    #-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
    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
    I am getting no constructor using javap tool in my, class here goes the output of my class... ๐Ÿ˜Ž
    [โ€‹IMG]
  • Anoop Kumar
    Anoop Kumar
    your code please...
  • Vikash Verma
    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
    Anoop Kumar
    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
    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\\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\\My Documents\Downloads>javap -private supe
    r1
    Compiled from "HelloWorld.java"
    class super1 extends java.lang.Object{
        super1();
    }
  • Vikash Verma
    Vikash Verma
    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
    Vikash Verma
    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[]);
    }
    And can you Please tell what is your code? B.java?
  • sookie
    sookie
    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
    my JDK giving error while running javap B.
    While "javap -private B". is working fine.
    #-Link-Snipped-# , can you confirm this.
  • sookie
    sookie
    ianoop
    my 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
    sookie
    show 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\\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
    sookie
    ianoop
    ๐Ÿ˜ฒ, its working, what's wrong , I was doing
    Cool...๐Ÿ˜€
  • Vikash Verma
    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 โ€‹โ€‹
๐ŸŽ‰๐Ÿ˜๐ŸŽ‰๐Ÿ˜๐ŸŽ‰๐Ÿ‘€๐Ÿ‘Žโ˜•๐Ÿ˜