Call constructor from another one?super class in subclass, JAVA Programming

Assignment Help:

2089_Untitled.png

 

What occurs if you do not give a constructor? Java does not actually need an explicit constructor in the class description. If you do not add a constructor, the Java compiler can create a default constructor in the byte code with an empty argument. This default constructor is same to the explicit “Pet(){}”. If a class add one or more explicit constructors like “Pet(){}” or “public Pet(int id)” etc, the java compiler does not prepare the default constructor “Pet(){}”.

 

How to call the superclass constructor in sub class? If a class called “SpecialSet” extends your “Set” class then you will use the keyword “super ” to invoke the superclass’s constructor. E.g.

 

public SpecialSet(int id)

{

super(id); //must be the very first statement in the other constructor.

}

To call a regular method in the super class need: “super .myMethod( );”. This may be called at any line. Some frameworks based on JUnit include their own initialization code, and not only do they need to remember to invoke their parent's setup() function, you, as a user, have to remember to invoke theirs after you wrote your initialization code:

 

public class UnitTestCase extends TestCase {

public void setUp() {

super .setUp();

// do class own initialization

}

}

public void cleanUp() throws Throwable

{

try {

… // Do stuff here to clean up your object(s).

}

catch (Throwable t) {}

finally{

super .cleanUp(); //clean up your parent class.

// super.regularMethod() can be called at any line.

}

}

 


Related Discussions:- Call constructor from another one?super class in subclass

What system.out.println() signifies, What 'System.out.println()' signifies?...

What 'System.out.println()' signifies? 'System' is a predefined class. System class gives access to the system. 'out' is the output stream. 'println' is printin

Write a java code to explain else if, Write a java code to explain Else If ...

Write a java code to explain Else If ? if statements are not limited to two cases. You can merge an else and an if to form an else if and test a overall range of mutually exclu

Java graphic application, I need to draw cars and trucks and background wit...

I need to draw cars and trucks and background with road and a house with sky. I have to use Vehicle class as a parent class. To draw pictures, i should draw fun things coming up

Rmi client program, In a RMI Client Program, what are the excpetions which ...

In a RMI Client Program, what are the excpetions which may have to handled Ans) a. MalFormedURLException b. NotBoundException c. RemoteException

Simple Java Project Please help, I have a project due tonight and I need he...

I have a project due tonight and I need help setting up the project I know what I need to put in the class but not sure how to set it up properly

Whatsapp bulk messenger to unlimited numbers, Whatsapp bulk messenger to un...

Whatsapp bulk messenger to unlimited numbers Project Description: Develop a desktop application or script solution to bulk whatsapp sms without getting any block from the wha

Write a xhtml document with java script, Write an XHTML document that uses ...

Write an XHTML document that uses JavaScript code to do the following.  The user is first prompted for a word and then for a possible prefix for that word.  If the prefix is not an

Write a function that draws a cow , Write a function that draws a cow at a ...

Write a function that draws a cow at a certain location on the screen, and use the function to draw a herd of cows

Write a program on filling rectangles, Write a program on Filling Rectangle...

Write a program on Filling Rectangles ? The drawRect() method draws an open rectangle, a box if you prefer. If you need to draw a filled rectangle, use the fillRect() method. O

Explain what occur when an object is created in java, Explain what occur wh...

Explain what occur when an object is created in Java?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd