answersLogoWhite

0

Search results

No. You must create a subclass of the abstract class in order to be able to instantiate it.

1 answer


int* pint; // instantiate a pointer to an int.

float* pflt; // instantiate a pointer to a float.

1 answer


The term 'instantiate' can be used in many different ways. The word 'instantiate' is a term meaning to provide an example. One way an individual might use the term is 'The mom instantiated how to tie her shoe.'

1 answer


According to a beginner's book on Java, an interface can't have constructors. Also, the interface itself can't contain the method implementation.

3 answers


Still have questions?
magnify glass
imp

No. An interface can only be implemented.

1 answer


-instantly

-instantaneous

-instantiate

-instants

1 answer



dim obj as object

obj = new object();

1 answer


No. You can declare a dynamic array without specifying a length, but in order to physically instantiate (either by using malloc or by using object-oriented construction) you must provide a length.

1 answer


When you do not want any other class to be able to instantiate your current class

1 answer


The exact same way you instantiate a class from any of the various Java libraries: by using the 'new' keyword.

i.e

MyClass A = new MyClass();

this forces the MyClass definition to run its Constructor method, and return an instance of object of type MyClass.

1 answer


The constructor of a Java class is not an ordinary method. Its purpose is not to return any value. The purpose of the constructor is to instantiate the class which it does.

Since, the purpose of a constructor is only to instantiate and initialize its class and not anything else, it does not have a return type. All it does is creates an object of that class.

1 answer


To instantiate a object, we use the new keyword in Java, which creates an object in memory.

1 answer


there would just be one instance of the object no matter how many times you instantiate it.

1 answer


It is an abstract class so you can't instantiate it directly, but have to use a subclass instead.

1 answer


No. Logic should never go in a constructor; constructors should only be used to instantiate and initialize object data.

1 answer


Yes, you can. Making a constructor private ensures that no other class can instantiate that class you just created with a private constructor. It is usually used in Singleton Patterns.

1 answer


A subclass invokes its base class constructor at the point of instantiation. That is; you cannot instantiate a subclass object without first constructing its base class, which is done automatically.

1 answer


An abstract class cannot have a constructor and hence you cannot invoke the constructor of the class - i.e., you can instantiate an abstract class and hence you cannot call the constructor of an abstract class.

3 answers


A constructor is not a function (it has no return value, not even void). As such you cannot call a constructor as you would a function. Constructors are always invoked automatically whenever an object of the class is instantiated.

For example:

struct S {

// ...class has implicit default constructor

};

static S s1; // instantiate an object of type S in static memory

void f () { S s2; // instantiate an object of type S on the call stack

} // s2 falls from scope here

void g() {

S* p = new S; // instantiate an object of type S on the heap

// ...

delete p; // release the object pointed to by p

} // p falls from scope here

int main() {

f(); // call function f

g(); // call function g

} // s1 falls from scope here

1 answer


An object is simply an instance of a class.

#include<iostream>

class my_object {};

int main()

{

my_object X; // instantiate an instance of the class my_object, identified as X.

}

1 answer


Instantiate means to create an actual instance of a Class. That is, the creation of an Object of that Class. This allocates memory on the heap for that object. Instantiate creates a unique object of that class, complete with its own copy of any class variables. Thing of a Class as a design spec, which, when instantiated, creates an actual thing of that type. For instance, imagine a set of blueprints detailing how a Ford Focus auto is to be manufactured. This is a Class. When those blueprints are manufactured (instantiated, in Java-speak), the result is a physically unique car. A class can be instantiated hundreds or thousands of times, but each instantiation creates a new and unique object, in the same way the Ford Focus blueprints can result in many individual cars.

In essence, it happens whenever you call:

new <ClassName>();

2 answers


You do not import classes. Classes are the definition of a type, and if you link to a library then all of its types are made available to your program. All you have to do is instantiate objects from those types: thus there is nothing to import.

1 answer


A constructor is not a mandatory member that we need to code specifically for a class. While creating a class, even if we miss out coding the constructor, Java would create a default constructor all by itself.

The constructor is usually the place where we initialize things that are required by the class. Hence it is a good practice to code the constructor for our class.

Tip: If you do not want anyone to instantiate your class, you can declare the constructor as private. In that way no other class can instantiate your class.

2 answers


Example:

void foo( MyClass& object ){} // function with call by reference signature

MyClass* p = new MyClass(); // instantiate a pointer to MyClass

foo( *p ); // call by reference using the pointer

1 answer


In two situations:

  1. You want the child class to provide certain behavior while making sure that certain other behavior is as you want it (Through the concrete methods that you create)
  2. You dont want any other class to be able to instantiate your class

1 answer


Yes. You cannot inherit a final class but very well instantiate a final class

3 answers


System defined constructor or Default constructor is the constructor that the JVM would place in every java class irrespective of whether we code it manually or not. This is to ensure that we do not have compile time issues or instantiation issues even if we miss declaring/coding the constructor specifically. Ex: public class Test { public String getName() { return "Rocky"l } Public static void main(String[] args){ Test obj = new Test(); String name = obj.getName(); } } Here we were able to instantiate the class Test even though we did not declare a no argument constructor. This is the default constructor that gets called when we try to instantiate it.

1 answer


You cannot create an instance of an abstract class. For ex:

Public abstract AbsTest {

…

}

AbsTest ex = new AbsTest();

Lets say we have a class declaration AbsTest that is abstract and then I try to instantiate it, the compiler will give me an error stating that "An Abstract class cannot be instantiated"

1 answer


Constructors have no value, zero or otherwise. That is, constructors cannot return a value. This is because constructors are not functions in the sense you cannot call a constructor directly. Constructors are invoked in the background when you instantiate an object of the class, thus any return value would be lost in the background, and would therefore not be visible to the invokee.

1 answer


Yes. Although dynamic binding occurs at runtime, the compiler ensures that all runtime instances are covariant with compile time types. That is, you cannot instantiate a base class pointer to a derived type that is not covariant with the base class. The derived type must have an "is-a" relationship or the compilation will fail.

1 answer


The main method is static because the JVM would be invoking this method as the starting point of execution. If this is like other normal methods, the JVM would have to instantiate an object of the class before it can call it. This is not possible because this is the starting point. If the main method is static the JVM can directly call this by specifying the class name.

1 answer


make sure to include the lib, to your space, or main, or however you are adding in your libs....

define and instantiate an odbc object. use a command such as objectname.connect, wrap it up in a conditional. If you need it to loop for some real time like update needs...thats acceptable.

1 answer


a specifier tells the JVM how to treat a particular class,method and variable while executing the program. For example, final classes cannot be extended and final methods cannot be overriden and final variables cannot be changed once declared. Likewise,static methods and variables can be accessed without having to instantiate an object for their class

1 answer


The keyword new is used to instantiate or create Java class objects.

ex:

String empName = new String("Rocky");

The above statement creates a new String object of name empName and value as Rocky

2 answers


The simplest way is to allocate raw memory of the required length using a pointer-to-pointer to the class of object. Once you have the memory, you can access the individual elements just as you would any other type of array, to either instantiate new objects or to point to existing objects.

The following example uses the class itself to allocate a dynamic array of a given size, via a static member function.

// Declare a simple class with a default constructor,

// one member variable and a static member function.

class MyClass

{

public:

MyClass():m_int(0){} // Default constructor initialises member variable.

private:

int m_int; // Member variable.

public:

static MyClass** CreateArray(unsigned int count); // Static member function.

};

// Implementation of the static member function.

MyClass** MyClass::CreateArray(unsigned int count)

{

MyClass** ppResult = NULL;

if( count )

{

// Calculate size of allocation.

size_t size = count * sizeof( MyClass* );

// Allocate memory and zero.

if( ppResult = ( MyClass** ) malloc( size ))

memset( ppResult, 0x00, size );

}

return( ppResult );

}

int main()

{

// Some variables.

int i = 0;

MyClass** ppArray;

// Instantiate objects in a fixed-size array (uses default constructor).

MyClass Array[10];

// Instantiate a dynamic array of objects (and check for NULL).

if( ppArray = MyClass::CreateArray( 10 ))

{

// Point array elements to the existing objects.

for( i=0; i<10; ++i )

ppArray[i] = &Array[i]; // Any existing object will do here.

// ...do stuff...

// Finished with dynamic array (does NOT destroy the existing objects).

delete( ppArray );

ppArray = NULL;

}

// Instantiate a new dynamic array (and check for NULL).

if( ppArray = MyClass::CreateArray( 5 ))

// Instantiate new objects via default constructor.

for( i=0; i<5; ++i )

ppArray[i] = new MyClass();

// Note: it's worth checking each element is not NULL before accessing it!

// ...do stuff...

// Destroy each object that was created.

for( int i=0; i<5; ++i )

{

delete( ppArray[i] );

ppArray[i] = NULL;

}

// Finished with dynamic array.

delete( ppArray );

ppArray = NULL;

}

return( 0 );

// Array[10] will now fall from scope...

}

1 answer


No. The abstract keyword means that you cannot instantiate the class unless you extend it with a subclass. The final keyword means that you cannot create subclasses of that class.

Combining them would lead to an unusable class, so the compiler will not let this happen.

2 answers


Because, the keyword static signifies the fact that the method or variable that is qualified using the static keyword is not attached to any object of the class. Therefore we cannot instantiate the class and use the object to reference to access it.

The only option we have is to use the class name to directly access them

1 answer


The keyword new is used to instantiate or create Java class objects.

ex:

String empName = new String("Rocky");

The above statement creates a new String object of name empName and value as Rocky

2 answers


You cannot copy constructor addresses because they are not functions. They have no return type and you cannot call them directly, so it makes no sense whatsoever to point at them. They are invoked automatically whenever you instantiate an object of the type, and that's all they will ever need to do. Pointing at them would serve no purpose, so the language simply does not allow it.

1 answer


A class is a type. Classes don't do anything except define the type. You have to instantiate an object of the type in order to actually do anything, including initialising data members. However, the class can define how a data member is initialised. The most efficient method of initialising class members if via the class constructor initialisation list.

1 answer


These concepts are two different things.

A 'Constructor' is a special method with the same class name and with no return type definition, invoked only when we create a new object (when we instantiate our object with the 'new' operator). An is used to initialize our object state (our instance variables).

A thread is a separate process which runs in parallel (at the same time) in a program.

1 answer


Never. A class is a type definition that only exists in the source code, so no storage is ever allocated to it. This can be proved by the simple fact that you can never take the address of a class.

When you instantiate an object from a class, the object and its members have identity thus you can take the address of that object and its members. Similarly, as soon as you use the static members of a class, you may take the address of those members. However the class itself does not exist; its sole purpose is to assist the compiler in generating the code that allows you to call static member functions and to instantiate objects of the class. Once that code is compiled, the class definition is entirely redundant.

2 answers


Because, the main method is the starting point of the java program and if we need an object of that class even before the main can be invoked, it is not possible. Hence it is declared static so that the JVM Can acess the main method without having to instantiate that particular class

2 answers


You can define and instantiate a thread in one of two ways:

• Extend the java.lang.Thread class.

• Implement the Runnable interface.

Ex:

class MyFirstThread extends Thread {

public void run() {

System.out.println("Important job running in MyFirstThread");

}

}

class MyFirstRunnableClass implements Runnable {

public void run() {

System.out.println("Imp job running in MyFirstRunnableClass");

}

}

1 answer


You can define and instantiate a thread in one of two ways:

• Extend the java.lang.Thread class.

• Implement the Runnable interface.

class MyFirstThread extends Thread {

public void run() {

System.out.println("Important job running in MyFirstThread");

}

}

or

class MyFirstRunnableClass implements Runnable {

public void run() {

System.out.println("Imp job running in MyFirstRunnableClass");

}

}

1 answer


Lightweight framework do not have to depend on framework interfaces or abstract classes to hook or instantiate components into them.

Heavyweight frameworks on the other hand require the extension of framework classes or the implementation of framework interfaces in order to take advantage of their middleware features.This means that a lot of classes are instantiated and hooked on to your application when they may not be even required!!

1 answer


You can define and instantiate a thread in one of two ways:

• Extend the java.lang.Thread class.

• Implement the Runnable interface.

Ex:

class MyFirstThread extends Thread {

public void run() {

System.out.println("Important job running in MyFirstThread");

}

}

class MyFirstRunnableClass implements Runnable {

public void run() {

System.out.println("Imp job running in MyFirstRunnableClass");

}

}

1 answer


An abstract class is designed to provide function and organization to subclasses without ever existing as an object itself. In other words, it is a glorified template, an abstraction for subclasses, and would be illogical to instantiate.

As an example, imagine that a zoo wanted to make separate classes representing each of its animals, but wanted them to all have some common features like a variable for life expectancy or a method to project feeding costs. To force every class to implement this functionality, the programmer may create an abstract class called Animal that each subclass would extend. However, would it ever make sense to create an Animal? No, because an Animal does not exist anywhere in the zoo - an Alligator however might.

3 answers


A constructor in a class is one of the first pieces of code to be executed when you instantiate a class. The purpose of constructors is to have code that initialize the class and prepare the variables that may be required by the class...

3 answers