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

Write code in a java for automaton distributed in class, Write a code in a ...

Write a code in a c++/java  for the automaton distributed in the class that accepts keywords(cat,bat,cab). Create an input file along with these words may be two or three copies of

What is the purpose to use the enableevents method, What is the purpose to ...

What is the purpose to use the enableEvents() method?

Gui-based event-driven application program, GUI-Based Application Object...

GUI-Based Application Objectives:   (1)   Learning how to write a GUI-based application in Java. (2) Learning how to write an event driven application program in Java.

How can you performance tune your database?, 1. De normalizes your tables w...

1. De normalizes your tables where required. 2. Proper use of index columns: An index based on numeric parts is more efficient than an index based on character columns. 3. Re

How to construct objects with new operator, How to Construct objects with n...

How to Construct objects with new operator? class Car { String licensePlate; // e.g. "New York 543 A23" double speed; // in kilometers per hour double maxSpeed;

Explain booleans in java, Explain Booleans in java? Booleans are named ...

Explain Booleans in java? Booleans are named after George Boole, a nineteenth century logician. Every boolean variable has one of two values, true or false. These are not the s

What is object oriented programming explain with an example, What is Object...

What is Object Oriented Programming explain with an example? In Java everything is an object or a class (or a piece of one or a collection of various). Objects send messages t

Application rewrite, Application Rewrite Project Description: There i...

Application Rewrite Project Description: There is an app that I want to be rewritten in order to support multiple profiles. The App is an OTP generator. It is required to

Prob, hi there I have some problem on java .. can u do it for me

hi there I have some problem on java .. can u do it for me

What is the function of network interface card, What is the function of Net...

What is the function of Network Interface Card? NIC is an I/O device which plugs within the computer and it enables it to communicate over a network.

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