answersLogoWhite

Top Answer
User Avatar
Wiki User
Answered 2011-09-15 11:45:44

These are two different things.

"Super" is used in inheritance - if class B inherits from class A, and we want the constructor of B to do the same things the constructor of A does (and maybe more things), we can call A's constructor in B's constructor:

public B() {

super();

......

}

Notice that it must be the first line in B's constructor.

"This" is used in case of overloading, to call a function aith the same name.

For example, if we have a constructor that receives one argument, and we it want to have a default value of 0, we can write:

public C() {

this(0);

}

001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Related Questions


When any constructor is deffined in your class, the java compiler create a default no argument constructor for you. This constructor only have an invocation to the super class constructor (" super( ) ").


Constructor is used to do something (written in constructor) immediately after object creation.


super keyword is used for two reasons: 1. To Call the super class or base class constructor 2.To call super class methods. If you don't create constructor in a class...Java automatically put for you. Always remember..that the first statement in derived class constructor must be a call to super or this.


No. Java does not support copy constructor


super is a keyword in java.uses of super are: 1.it is used to call super class constructor. 2.It is used to call a method of super class that is hidden by sub-class.


To create objects of classes


The default constructor is an empty (only call the super constructor) with no parameters constructor inserted by the java compiler when you don't define a constructor in your class. If you write something like this: public class NoConstructorClass{ //no constructor goes here } Then you get something like this: public class NoConstructorClass{ public NoConstructorClass(){ // Default constructor that you didn't write super(); } }


In the case of Java, not always. The class does require a constructor, but the compiler will automatically include an "empty constructor" (constructor without parameters) under certain conditions.In the case of Java, not always. The class does require a constructor, but the compiler will automatically include an "empty constructor" (constructor without parameters) under certain conditions.In the case of Java, not always. The class does require a constructor, but the compiler will automatically include an "empty constructor" (constructor without parameters) under certain conditions.In the case of Java, not always. The class does require a constructor, but the compiler will automatically include an "empty constructor" (constructor without parameters) under certain conditions.


A Private constructor is simply a constructor that can only be used within the class it was declared in. By default java creates you a constructor which is public though. Hope that helps


It is also called the default constructor. It is the constructor that the java compiler places in every class where the programmer has not explicitly coded a constructor. Ex: public class Car { ... //lots of code but no constructor } If a person writes a class as above, then the compiler places this code in the compiled version of the file. public Car() { super(); } This is called the non-parameterized or default constructor


When the programmer has not coded a constructor for any java class.


Because, the parent class also needs to be initialized when you create an object in the inheritance hierarchy.


by the use of constructor . we can initialize the variables in java.The name of the constructor should be same as the name of the class .


A constructor is a method that is invoked when an object is created. As to being mandatory, that really depends on the programming language; in the case of Java, each class must have a constructor, however, in many cases Java will automatically provide a default constructor, so you don't really need to program it.


All Java programs would have a constructor... public class Test { public Test(){ ... } ..... } This is a constructor. Even if you dont code the constructor Java would automatically place a default constructor for compilation.


What are the importance of constructor in java? Constructor is automatically called immediately after the object is created , before the new operator complete . Constructor is important because they have no return type , not even void.


No. The constructor is the starting point of creation of any object in Java. Without going through a constructor you cannot create an object


Default Constructor Parameterised Constructor Non Parameterised Constructor


Yes you can but it is not required. A Servlet is nothing but another .java file and all rules that are applicable to standard Java classes are applicable to them. Note: Even if you write a constructor in a servlet, it will not get executed.


Classes in Java inherit constructors from their parent classes. If you don't explicitly define a parent class, then Object is used, which has only the default empty constructor. That "default" constructor is only there when defined by the parent class, so classes which do not have a no-argument constructor will not allow subclasses to automatically use it. This is implemented this way because of the special nature of constructors. Java could not always provide a default constructor because it could not guarantee that all class members would be properly created or initialized.


It may be because you are using inheritance and your super class constructor has a throws clause in its declaration. If your super class has a throws clause in its constructor declaration, you must do the same in your child class constructor in order to eliminate this compiler error.


Constructors in java cannot be invoked explicitly. They are invoked automatically when an object is created. In java if u dont write any code for constructor, by default compiler inserts a zero argument constructor. If required, it can be overrided.


No. if you wish to create an object that you plan on using in a java program then the answer is NO. You cannot initialize an object of a Java class without calling the constructor.


It is the way to create the instances of class. in java. to know how constructor works first you should be clear with the concept of class.


When we want to create an Object for a class at that time we will write constructor.



Copyright ยฉ 2021 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.