answersLogoWhite

0

How do we declare objects?

Updated: 8/18/2019
User Avatar

Wiki User

14y ago

Best Answer

In Java, write the name of a class, followed by a variable name. For example:

String myName;

This won't actually create the object; you also need to create the object:

myName = new("Hi, it's me.");

These two parts (declaration, and object creation) can be combined:

String myName = new String("Hi, it's me.");

(In the case of a String, in Java you can just assign a quoted string, instead of using the new operator. However, I wanted to show the general syntax for object creation, that works for other kinds of objects too.)

In Java, write the name of a class, followed by a variable name. For example:

String myName;

This won't actually create the object; you also need to create the object:

myName = new("Hi, it's me.");

These two parts (declaration, and object creation) can be combined:

String myName = new String("Hi, it's me.");

(In the case of a String, in Java you can just assign a quoted string, instead of using the new operator. However, I wanted to show the general syntax for object creation, that works for other kinds of objects too.)

In Java, write the name of a class, followed by a variable name. For example:

String myName;

This won't actually create the object; you also need to create the object:

myName = new("Hi, it's me.");

These two parts (declaration, and object creation) can be combined:

String myName = new String("Hi, it's me.");

(In the case of a String, in Java you can just assign a quoted string, instead of using the new operator. However, I wanted to show the general syntax for object creation, that works for other kinds of objects too.)

In Java, write the name of a class, followed by a variable name. For example:

String myName;

This won't actually create the object; you also need to create the object:

myName = new("Hi, it's me.");

These two parts (declaration, and object creation) can be combined:

String myName = new String("Hi, it's me.");

(In the case of a String, in Java you can just assign a quoted string, instead of using the new operator. However, I wanted to show the general syntax for object creation, that works for other kinds of objects too.)

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

In Java, write the name of a class, followed by a variable name. For example:

String myName;

This won't actually create the object; you also need to create the object:

myName = new("Hi, it's me.");

These two parts (declaration, and object creation) can be combined:

String myName = new String("Hi, it's me.");

(In the case of a String, in Java you can just assign a quoted string, instead of using the new operator. However, I wanted to show the general syntax for object creation, that works for other kinds of objects too.)

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do we declare objects?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you declare an object inside static number function in c?

No, because there are no objects in C.


In DevCplusplus Allegro Id like to use a for loop so you can draw multiple primitives without having to declare each one could anyone tell you how to do that?

You only have to declare objects if you intend to store them. If you simply want to draw objects without storing them, then use static drawing methods in your loop.


What is out of scope in returning objects in java?

if u declare variable in method & tray to use this variable outside the method then it is out of scope


Can you declare constructor as constant if yes why?

Constructors are implicitly constant members of a class. They do not modify objects, rather they initialize them. So constant and not constant objects can invoke them: const MyClass object; // invokes MyClass::MyClass() constructor


What is String Str?

Str is probably a String variable declared. Usually when we declare String objects we prefix it with the character str. example: String strName = "";


How do you write classes and objects for hospital management software using objective c or c plus plus?

You declare a class as follows: class MyClass { //some stuff here... } You create an object as follows: MyClass object; This is how you create classes and objects in C++.


To declare positively?

to declare positively


How do you declare war in evony?

you declare war


When was Declare created?

Declare was created in 2001.


What is an example of a sentence with the word declare?

The president will declare a state of emergency in response to the natural disaster.


What declare laws unconstitutional?

Who can declare laws unconstitutional


How many pages does Declare have?

Declare has 517 pages.