Question

Hello, What is the answer to this Java question? Which​ ​of​ ​the​ ​following​ ​is​ ​false​ ​with​...

Hello,

What is the answer to this Java question?

Which​ ​of​ ​the​ ​following​ ​is​ ​false​ ​with​ ​respect​ ​to​ ​local​ ​variables?

a. Their​ ​lifetime​ ​is​ ​the​ ​execution​ ​time​ ​of​ ​the​ ​method​ ​they​ ​are​ ​declared​ ​in

b. Their​ ​scope​ ​is​ ​the​ ​method​ ​they​ ​are​ ​declared​ ​in

c. They​ ​are​ ​not​ ​auto-initialised​ ​unless​ ​they​ ​are​ ​elements​ ​of​ ​an​ ​array

d. They​ ​must​ ​be​ ​primitive

e. They​ ​cannot​ ​have​ ​the​ ​same​ ​name​ ​as​ ​an​ ​instance​ ​variable​ ​in​ ​the​ ​same​ ​class

f. Select​ ​this​ ​option​ ​if​ ​you​ ​think​ ​more​ ​than​ ​one​ ​of​ ​the​ ​above​ ​false

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The first statement is correct as the lifetime of local variables is always during ​the​ ​execution​ ​time​ ​of​ ​the​ ​method​ ​they​ ​are​ ​declared​ ​in.

The second statement is true that is their scope​ ​is​ ​the​ ​method​ ​they​ ​are​ ​declared​ ​in.

public static void Func1( int a, int b)

{

int r=a*b;

System.out.println(r);

}

public static void Func1( )

{

}

Here, the variable r has its scope and execution local to its execution method.

The third statement is also true as the local variables are used for specific purposes and it cannot have any kind of default value.

The fourth option is correct as non primitive variables are not locally defined in a function but are created by the programmer itself. So, local variables must be primitive.

The fifth option is also not correct as the name of local variable can be same as that of an instance variable in the same class.

Thus, the false statement is option e.

Add a comment
Know the answer?
Add Answer to:
Hello, What is the answer to this Java question? Which​ ​of​ ​the​ ​following​ ​is​ ​false​ ​with​...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java For the following, state whether the following statement is true or false, if false explain...

    Java For the following, state whether the following statement is true or false, if false explain the reason briefly and state the complete, correct statement. a) Data type boolean is compatible with, and can be converted to, any other data type. b) Java automatically converts primitive types into their class wrapper objects. c) In creating objects using default constructors, class instance variables are initialized to their default values.

  • Create another Java class named EmployeeMain within the same project, which includes the main method. a....

    Create another Java class named EmployeeMain within the same project, which includes the main method. a. Include another class named Employee in the same Java file. This class has the following instance variables and instance methods. Define all the instance/static variables with private access modifier and constructors, instance/static methods with public access modifier. Instance Variables empID: int employeeName: String basicSalary: double Constructor Set the value for empID. Instance Methods Get and set methods for all instance variables. displayEmployee: Display the...

  • Question 1 1 pts Which of the following is not a valid class name in Java?...

    Question 1 1 pts Which of the following is not a valid class name in Java? O MyClass MyClass1 My_Class MyClass# Question 2 1 pts Which of the following statements is False about instance variables and methods? Instance variables are usually defined with private access modifier. Instance variables are defined inside instance methods. Instance methods are invoked on an object of the class that contains the methods. A class can have more than one instance variables and methods. Question 3...

  • Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal...

    Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal (POJo, JavaBean) class to represent, i. e. model, varieties of green beans (also known as string beans or snap beans). Following the steps shown in "Assignment: Tutorial on Creating Classes in IntelliJ", create the class in a file of its own in the same package as class Main. Name the class an appropriate name. The class must have (a) private field variables of appropriate...

  • Besides answering, please explain why that is the answer. java Question 8. The relationship between a...

    Besides answering, please explain why that is the answer. java Question 8. The relationship between a class and an object is best described as a) classes are instances of objects b) objects are instances of classes c) objects and classes are the same thing d) classes are programs while objects are variables e) objects are the instance data of classes Question 10. Assume that we have the class Airplane. A 3-by-4 two-dimensional array of objects of the class Airplane is...

  • Java Object Array With 2 Elements In 1 Object

    1. Create a UML diagram to help design the class described in Q2 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Person class object; should they be private or public? Determine what class methods are required; should they be private or public?2. Write Java code for a Person class. A Person has a name of type String and an age of type integer.Supply two constructors: one will be...

  • JAVA QUESTION 16 Write and submit the java source for the following class specification: The name...

    JAVA QUESTION 16 Write and submit the java source for the following class specification: The name of the class is Question_16 Class Question_16 has 3 instance variables: name of type String, age of type int and height of type double. Class Question_16 has the following methods: print - outputs the data values stored in the instance variables with the appropriate label setName - method to set the name setAge - method to set the age setHeight - method to set...

  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

  • Part Two: Fill in the Blanks and True/False (24 total points - 2 points each) For...

    Part Two: Fill in the Blanks and True/False (24 total points - 2 points each) For each of the following, fill in the most appropriate word(s)phrase/solution in each blank 1) Keywords, identifiers and literals are all kinds of are simply groups of characters that are used for various purposes in a program. , which 2) The Java expression: 11 - 2 + 3 evaluates to 3) List the Java boolean (logical) operators in order from highest priority to lowest priority...

  • Hello, What is the answer to this Java question? After​ ​the​ ​following​ ​declaration:​ ​​People[]​ ​crowd​ ​=​...

    Hello, What is the answer to this Java question? After​ ​the​ ​following​ ​declaration:​ ​​People[]​ ​crowd​ ​=​ ​new​ ​People[10]; What​ ​is​ ​the​ ​value​ ​of​ ​​crowd[0]​? a) Undefined b) The​ ​address​ ​of​ ​a​ ​People​ ​object c) The​ ​address​ ​of​ ​a​ ​crowd​ ​object d) null e) Select​ ​this​ ​option​ ​if​ ​you​ ​think​ ​​crowd[0]​ ​​has​ ​invalid​ ​syntax

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT