1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
bagirrra123 [75]
3 years ago
15

What is a Java constructor?

Computers and Technology
2 answers:
Elden [556K]3 years ago
6 0

A Java constructor is special method that is called when an object is instantiated. In other words, when you use the new keyword. The constructor initializes the newly created object.

Alina [70]3 years ago
3 0

Answer:

Java constructor is a special method defined in a class whose name s the same as the class name

Explanation:

Java constructor is a special method defined in a class whose name is the same as the class name.

The constructor is called when the object is instantiated to initialize the fields in the object. Constructor can have no arguments or it can carry one or more arguments as per the class design. A default no argument constructor is made available for a class automatically even if one is not explicitly defined.

For example: MyClass c = new MyClass();

This will call the zero argument constructor of MyClass if it is defined or otherwise the default constructor for MyClass.

You might be interested in
1. Print out the string length of s1 2. Loop through characters in s2 with charAt() and display reversed string 3. Compare s2, s
konstantin123 [22]

Answer:

See explaination

Explanation:

public class StringLab9 {

public static void main(String args[]) {

char charArray[] = { 'C', 'O', 'S', 'C', ' ', '3', '3', '1', '7', ' ', 'O', 'O', ' ', 'C', 'l', 'a', 's', 's' };

String s1 = new String("Objected oriented programming language!");

String s2 = "COSC 3317 OO class class";

String s3 = new String(charArray);

// To do 1: print out the string length of s1

System.out.println(s1.length());

// To do 2: loop through characters in s2 with charAt and display reversed

// string

for (int i = s2.length() - 1; i >= 0; --i)

System.out.print(s2.charAt(i));

System.out.println();

// To do 3: compare s2, s3 with compareTo(), print out which string (s2 or s3)

// is

// greater than which string (s2 or s3), or equal, print the result out

if (s2.compareTo(s3) == 0)

System.out.println("They are equal");

else if (s2.compareTo(s3) > 0)

System.out.println("s2 is greater");

else

System.out.println("s3 is greater");

// To do 4: Use the regionMatches to compare s2 and s3 with case sensitivity of

// the first 8 characters.

// and print out the result (match or not) .

if (s2.substring(0, 8).compareTo(s3.substring(0, 8)) == 0)

System.out.println("They matched");

else

System.out.println("They DONT match");

// To do 5: Find the location of the first character 'g' in s1, print it out

int i;

for (i = 0; i < s2.length(); ++i)

if(s2.charAt(i)=='g')

break;

System.out.println("'g' is present at index " + i);

// To do 6: Find the last location of the substring "class" from s2, print it

// out

int index = 0, ans = 0;

String test = s2;

while (index != -1) {

ans = ans + index;

index = test.indexOf("class");

test = test.substring(index + 1, test.length());

}

System.out.println("Last location of class in s2 is: " + (ans + 1));

// To do 7: Extract a substring from index 4 up to, but not including 8 from

// s3, print it out

System.out.println(s3.substring(4, 8));

} // end main

} // end class StringLab9

7 0
3 years ago
Write a function DrivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar
posledela

Answer:

#include <iostream>

using namespace std;

double DrivingCost(int drivenMiles,double milesPerGallon,double dollarsPerGallon)

{

   double dollarsperMile=dollarsPerGallon/milesPerGallon;//calculating dollarsperMile.

   return dollarsperMile*drivenMiles;//returning thr driving cost..

}

int main() {

double ans;

int miles;

cout<<"Enter miles"<<endl;

cin>>miles;

ans=DrivingCost(miles,20.0,3.1599);

cout<<ans<<endl;

return 0;

}

Output:-

Enter miles

10

1.57995

Enter miles

50

7.89975

Enter miles

100

15.7995

Explanation:

In the function first I have calculated the dollars per mile and after that I have returned the product of dollarspermile and driven miles.This will give the cost of the Driving.

4 0
2 years ago
What standards organization maintains the ethernet standard?.
Fofino [41]

Answer:

Ethernet standards are written and maintained by the IEEE, the Institute of Electrical and Electronic Engineers which has its corporate office in New York City and its operations center in Piscataway, New Jersey.

Explanation:

5 0
2 years ago
What is cloud computing?
Luba_88 [7]
According to google, cloud computing. <span>the practice of using a network of remote servers hosted on the Internet to store, manage, and process data, rather than a local server or a personal computer.</span>
4 0
3 years ago
What are the advantages and disadvantages of globalization and new technologies?
snow_lady [41]

Answer:

the advantage is the better the tech. the easier life gets

the disadvantages is the better it gets. the more danger it puts us in (depending on the tech) and the more lazy we become

7 0
3 years ago
Other questions:
  • 1. Isabella is a security support manager for a large enterprise. In a recent meeting, she was asked which of the standard netwo
    7·1 answer
  • After a normal system shutdown, when the computer is turned off, contents of the memory used to store bios settings are
    12·2 answers
  • Why is color theory important
    6·2 answers
  • Which evaluation factor will be most important when choosing technology for the company
    5·1 answer
  • Help please fast
    6·2 answers
  • Ricardo twists his ankle at work but does not immediately realize that he is injured because his ankle is not sore or swollen, a
    5·1 answer
  • Directory services store information in a heirarchical structure. Which statements about Organizational Units (OUs) of a directo
    13·1 answer
  • 19 dollar fortnite gift card
    14·2 answers
  • How am i able to hear a presenter from a radio station through my fm tuner​
    14·1 answer
  • Change the file name for index.html to index.php
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!