Question 1 Please answer by choosing the best match for each description. Used t
ID: 3586204 • Letter: Q
Question
Question 1 Please answer by choosing the best match for each description. Used to invoke inherited methods that are overridden in a subclass, or to Choose When you call a method, the receiver determines which how to respond (that is, determines which implementation of the method will be executed) Used to store information (objects or values) inside an object to represent the object's state. Choose Used to indicate that a method does not return a value, and instead represents a command. Choose A temporary name inside a method, used to refer to an object or valueCh in one or more places within that method. oose ] Stands for nothing, or no object Choose An object or value passed into a method to provide additional information the method needs in order to run. ChooseExplanation / Answer
Answer 1) super
super keyword is used to reference the instance variables, methods and constructors of immediate parent class. Let's suppose a very simple example.
class Vehicle
{
public String medium = "Water"; //Could be "Road" , "Water" or "Air"
public Vehicle(){
System.out.println("Medium is : " + medium);
}
}
public class Car extends Vehicle
{
public Car(){
super(); //Calls the Vehicle class constructor
super.medium = "Road"; // I can also directly access the medium instance variable since it is a public member
}
}
Answer 2) Polymorphism
Going by textbook definition it just means ability of a program to process a data in different forms. Dynamic binding is a better example
of polymorphism as the method to be executed is determined at run time.
Example:
class Vehicle
{
public void displayClass(void){
System.out.println("I am a Vehicle");
}
}
class Car extends Vehicle
{
public void displayClass(void){
System.out.println("I am a Car");
}
}
Let's say i create a Vehicle reference which references a Car object and try to call the displayClass() method.
Vehicle v = new Car();
v.displayClass(); // This call to displayClass() method prints "I am a Car" because it references a Car object rather than a Vehicle object.
Hence, depending on the type of object referred by the Vehicle reference variable "v" the method to be executed is determined.
Answer 3) Field
The contents of a class can be broadly classified into two categories, Instance variables or fields and methods. A field values actually defines
the current state of the object using the data it holds of the defined type. Methods process these fields to obtain desired output.
Let's define a class with a single field.
public class toss
{
public String outcome; // Could be "Heads" or "Tail"
}
Now an object of "toss" class would represent outcome of a toss depending on the field value of "outcome".
Answer 4) void
when a method doesn't return anything then the return type of such methods are represented as "void".
e.g: void displayResult(int result);
void can also be used to show that a method doesn't accept any parameters too
e.g: void displayResult(void);
Answer 5) local variable
local variables provides the means by which a method stores a computed value or information for later use.
e.g:
public void display(int val)
{
int value = (val / 2); // "value" is a local variable holding the outcome of a computation
System.out.println("Value : " + value);
}
Answer 6) null
null is used to represent an absence of value in an object.
e.g : Car benz = null;
This means "benz" doesn't refer to any physical object in memory.
Answer 7) parameter
"parameters" are used to provide additional information to method for it's functioning. Let's say we have a method which returns the square
of a number.
e.g:
int square(int value)
{
return (value * value);
}
we need to pass a number to this method to actually compute the square.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.