Why is a superclass constructer called automatically?

I have two simple classes as shown:
public class Class1 {
public Class1() {
System.out.println("Hello World");
public class Class2 extends Class1 {
public Class2() {
static public void main(String[] args) {
Class2 c2 = new Class2();
When I run Class2 (i.e. java Class2) it prints out "Hello World". It looks as though the constructor for class 2 is automatically calling the constructor from its superclass (class 1). I thought that you had to specify this with super(). Any Advice?

this should be in new to java programming.
anyway, the constructor of the super class need to be call automatically so that the object is in the proper state. suppose you extends from JFrame with class call MyJFrame. when you create your MyJFrame the code that construct the JFrame must be automatically called so that it works fine, after the constructor of the super class get called to initialize it's data then your subclass can initialize its own data. the constructor that is called automatically is the no-argument constructor. so if your super class does not have no-argument constructor you must explicitly call the appropiate super constructor in your subclass. also you cannot create instance of subclass that extends from the super class that has only private no-argument constructor.

Similar Messages

  • I need a app which can record incoming and outgoing calls automatically without internet

    i need a app which can record incoming and outgoing calls automatically without internet.
    Can some help me on this ?

    As far as I know there is no app to record phonecalls because US regulations, but I am not using iphone in US so we definately need call recorder. HTC or Samsung has call recorder so why we dont?

  • Why the method can be called in this way?

    Hi all,
    The following is JAVA SWING TREE custom data models program. There are two files in the program: one is TestFrame.java, and the other is MyDataModel.java. I only posted the important part on the Forum.My question is how method getChild(...) in MyDataModel.java was called in the program? Why I couldn't see the statement like tree.getChild(..) in TestFrame.java? After adding PRINT statements, I know the method getChild(..) was called automatically when object tree was initialized , but I don't know why. Thank you in advance.
    ======
    TestFrame.java
    // Imports
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    class TestFrame extends JFrame
    // Instance attributes used in this example
    private JPanel topPanel;
    private JTree tree;
    private JScrollPane scrollPane;
    // Constructor of main frame
    public TestFrame()
    // Create a new tree control
    MyDataModel treeModel = new MyDataModel( root );
    tree = new JTree(treeModel);
    =========
    ==========
    MyDataModel.java
    import javax.swing.tree.*;
    class MyDataModel extends DefaultTreeModel
    private DefaultMutableTreeNode root;
    private String rootName = "";
    public MyDataModel( TreeNode root )
    super( root );
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)root;
    rootName = (String)parentNode.getUserObject();
    System.out.println("rootName is: "+rootName);
    public Object getChild( Object parent, int index )
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)parent;
    String parentName = (String)parentNode.getUserObject();
    System.out.println("parentName is: "+parentName);
    if( parentName.equals( rootName ) )
    return super.getChild( parent, index );
    else
    return new DefaultMutableTreeNode( cardArray[index] );
    }

    This is the first time I saw this usage. I understood it now, but I was afraid I missed some important concepts on "interface as parameter in the constructor". Therefore, I am wondering where I can find some online document about it in order to understand the usage clearly.
    For example, if there are a few method implementations of interface TreeModel in MyDataModel.java, which methods will it call after calling JTree constructor? all methods or only part of them?
    Thanks

  • SSAS Tabular - Why is it wrong to call classify it as MOLAP, ROLAP or HOLAP?

    Hi There,
    I am working on an assignment (for a masters degree) in which I am evaluating different OLAP tools, and one of the tools assigned to me is Microsoft's BI stack.
    One of the classifications we are working on is whether a tool is MOLAP, ROLAP or HOLAP. When reading about SSAS Tabular, however, every single thing I read points out that SSAS escapes this traditional classification.
    I am trying to understand why would it be wrong to attempt to classify a Tabular instance of SSAS in such way? Why not say that SSAS Tabular is MOLAP, when using DirectQuery it is ROLAP, and if mixing both it is HOLAP?
    What is so fundamentally wrong about it?
    EDIT: Ah, and how does the Microsoft BI Semantic Model
    fits into the picture -- I assume is has something to do with the Tabular model being outside the traditional MOLAP/ROLAP/HOLAP classifiction?
    Thanks in advance for your help!
    Regards,
    P.

    Hi Pmdci,
    According to your description, you are looking for the reason why is it wrong to call classify SQL Server Analysis Service Tabular as MOLAP, right? As you know in MOLAP, data is stored in a multidimensional cube. The storage is not in the relational database,
    but in proprietary formats. And in ROLAP, data stored in the relational database to give the appearance of traditional OLAP's slicing and dicing functionality. However tabular solutions use relational modeling constructs such as tables and relationships for
    modeling data, and the xVelocity in-memory analytics engine for storing and calculating data. So as per my understanding, we cannot classify tabular as MOLAP.
    Reference:
    MOLAP, ROLAP, And HOLAP
    Comparing Tabular and Multidimensional Solutions (SSAS)
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here.
    Charlie Liao
    TechNet Community Support

  • Why does skype forward my calls

    Why does skype forward my calls to my skype number when I am online?

    Hi sydneysmith1234,
    I can see in your account that you have an active calling subscription. Please note that subscriptions renew automatically, as stated in our Terms of Use. You will be charged for it's renewal depending on the period you selected. Please refer to the private message I sent to you for further details.
    To check your private message, just go to Skype Community home page (community.skype.com), scroll at the bottom of the page. You will see "Private Message" just above "Users Online."
    Due to the time it can take for some transactions to be processed, we charge you three days in advance to ensure prompt delivery of your subscription. You do not lose these three days: your subscription is still valid for the full period that you sign up for.
    Your subscription will renew even if you are not using it. Skype subscription is the same with other subscriptions like cables, telephones, etc., wherein you are automatically charged for their renewal.
    For more information on how subscriptions work, you may refer to this link: https://support.skype.com/en/faq/FA10414/
    If answer was helpful please mark it with Kudos and if issue is resolved mark it with solution. This will help other users find this answer more easily. Thanks in advance!

  • OnDisconnect function called automatically at any time.

    onDisconnect function called automatically at any time on script side. Any body have any idea why it's getting called at random time. Please tell us how to handle this situation.

    In your client side script in onStatus handler of netconnection when you get status as NetConnection.Connect.Closed then create new netconnection object and relate all client functions to this new object like nc.client.doThis = doThis where doThis are functions on nc object.
    Something like this :
    if(info.code=="NetConnection.Connect.Closed"){
      nc = new NetConnection();
      if(nc){
       trace("Reconnect");
       nc.connect("rtmp://a.b.c.d/app");
      else{
       trace("Error:NetConnection not initilized");
    Regards,
    Amit

  • Macbook pro keeps saying connection timeout, and it used to connect to the internet fine. what's up, why can't it find and automatically connect to the internet anymore???

    Macbook Pro keeps saying connection timeout and it used to connect to the internet fine. What's up, why can't it find and automatically connect to the internet anymore???

    Like this: https://discussions.apple.com/thread/2775868?tstart=0  ?

  • Why does iTunes no longer open automatically when iPad is connected?

    Why does iTunes no longer open automatically when iPad is connected? and iPhone as well?  Setting to "auto open" is selected, but iTunes will not open automatically. Problem seems to have begun with upgrade to Lion.

    Good luck getting an answer...I posted the same question a day ago.   I can only assume it's a glitch in iTunes 10.5.

  • Why copy option from recent call numbers is not working on ios7 [recent call logs in phone]?

    why copy option from recent call numbers is not working on ios7 [recent call logs in phone]?

    Here is a copy of my expressions and a copy of my data. The expressions match up going from left to right
    Code.CalcPTD2(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"DataSet4"))
    sum(Code.CalcPTD2(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"DataSet4")))
    count(Code.CalcPTD2(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"DataSet4")))
    PUBLIC SHARED FUNCTION CalcPTD2(LookupArray AS OBJECT) AS INTEGER
         DIM i,Total AS INTEGER
         Total = 0
         FOR i = 0 to UBOUND(LookupArray)
               Total = Total + CINT(LookupArray(i))
         NEXT i
     NumberTimes  =   NumberTimes +1
    RETURN  Total
    END FUNCTION

  • Why ipad or ipad mini has no calling facility when wifi cellular is mentioned in specifications and also why do they never provide calling facility for their tablets?

    wifi+cellualr is clearly mentioned in ipad n ipad mini then why is there no calling facility?why does apple never provide calling facilities like other company tabs?

    A.P.D wrote:
    stedman1:yeah i know that.my question is why doesn't it provide?i mean cellular means it should be having calling facilities right?and if it doesn't have and will never have calling facility then why add cellular in specifications.i mean it's just confusing and i guess i'm not the only person to ask this question,m i?
    The term cellular means cellular data only, there has never been a telephone capability built in to the iPad WiFi+cellular models.
    You must arrange cellular data coverage with your cellular carrier or another cellular carrier to use the cellular data capability of the iPad.

  • Is it possible to accept an incomming call automatically?

    I am using my iPhone 4 or 5 while driving a car. Is it possible to accept an incomming call automatically?

    No

  • Why dose not see the call waiting notification when other party in a call with some one ?

    why dose not see the call waiting notification when other party in a call with some one ?

    Because that is not a feature of the iPhone (or of most phones). If someone does not answer when you call, it means they do not want to or cannot talk to you at that time. They could be on another call or they could be simply busy doing something else. Why does it matter which?

  • Why are mysterious dk.html files automatically downloading upon launch of newly updated Safari Version 5.1.7 (6534.57.2)?

    Why are mysterious dk.html files automatically downloading upon launch of newly updated Safari Version 5.1.7 (6534.57.2)?  I updated last night and ever since, these files download as soon as I launch Safari.

    I've gotten these from multiple web sites, including Drudge and National Journal.
    It is my opinion that this behavior is a side effect of the latest Java update. Until this latest update, Apple has maintained its own version of Java. The latest update is Oracle Java.
    Apple's note on the Java for Mac OS X 10.6 update 11 includes this:
    On systems that have not already installed Java for Mac OS X 10.6 update 9 or later, this update will configure web browsers to not automatically run Java applets. Java applets may be re-enabled by clicking the region labeled "Inactive plug-in" on a web page. If no applets have been run for an extended period of time, the Java web plug-in will deactivate. 
    Looking at the innards of one file downloaded, it appears to be a JavaScript beacon from advertising.com for rubiconproject.com. These files are used to track web browsing activity. I suspect that this Java changed the way the beacon is served and Safari.

  • Why do we need to call start() to execute a thread.

    hi,
    Why do we need to call thread.start() to execute a thread. why not just calling run().
    Vjoy

    hi,
    Why do we need to call thread.start() to execute a
    thread. why not just calling run().
    Because, start() does two things.
    - start a new thread of execution and then
    - call the run method....and calling run does NOT start a new thread of execution. It's just a plain old regular method.

  • Why is the fb video call doesnt work with macbook?

    why is the fb video call doesnt work with macbook?

    Hi
    Just to correct GerdW - the vis of a polymorphic vi do not have to have the same output.
    Have a look at the vis I attached. I just pass a dbl to a polymorphic vi and get a dbl in one vi and a string in the other.
    The real problem is that the vi has to be set to the necessary type. If there are different inputs you just can wire them to the polymorphic vi, but this does not work with the outputs, so you have to set the type.
    Hope this helps.
    Thomas
    Using LV8.0
    Don't be afraid to rate a good answer...
    Attachments:
    Polymorph.zip ‏14 KB

Maybe you are looking for