Question: public class Greetings { private String greetings; public Greetings ( String greeting ) { greetings = greeting; System.out.println ( greetings ) ; } public void

public class Greetings
{
private String greetings;
public Greetings(String greeting)
{
greetings = greeting;
System.out.println(greetings);
}
public void hello()
{
System.out.println("Hello");
}
public void translate()
{
greetings = "Hola";
}
public void changeGreeting(String greeting)
{
greetings = greeting;
}
public void greeting()
{
System.out.println(greetings);
}
}
Which of the following code segments will produce this output in the console:
"Hello"
"Hola"
I.
Greetings hi = new Greetings("Hello");
hi.translate();
hi.greeting();
II.
Greetings.hello();
Greetings.translate();
Greetings.greeting();
III.
Greetings hello = new Greetings();
hello.hello();
hello.translate();
hello.greeting();
IV
Greetings hola = new Greetings("Hello");
hola.changeGreeting("Hola");
hola.greeting();
Consider the following class:
public class Greetings
{
private String greetings;
public Greetings(String greeting)
{
greetings = greeting;
System.out.println(greetings);
}
public void hello()
{
System.out.println("Hello");
}
public void translate()
{
greetings = "Hola";
}
public void changeGreeting(String greeting)
{
greetings = greeting;
}
public void greeting()
{
System.out.println(greetings);
}
}
Which of the following code segments will produce this output in the console:
"Hello"
"Hola"
I.
Greetings hi = new Greetings("Hello");
hi.translate();
hi.greeting();
II.
Greetings.hello();
Greetings.translate();
Greetings.greeting();
III.
Greetings hello = new Greetings();
hello.hello();
hello.translate();
hello.greeting();
IV
Greetings hola = new Greetings("Hello");
hola.changeGreeting("Hola");
hola.greeting();
I, III and IV
IV only
I and III
I and IV
II only

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!