Concept explainers
This type of method cannot access any non-static member variables in its own class.
- a. instance
- b. void
- c. static
- d. non-static
Static methods cannot be accessed by any non-static member variable within a class
Hence, the correct answer is option “C”.
Explanation of Solution
Static method:
Static is an access modifier which cannot be accessed and is applicable on block, variable, methods, nested classes. Static keyword is added while declaring the block or variable or methods. A static member can be accessed before any objects of its class are created, and without even using the reference to any object.
Explanation for incorrect options:
a. Instance:
Instance variables are declared without the static keyword and are present outside any method declaration.
Hence, the option “A” is wrong.
b. Void:
it describes the return type of the method, where void means the method has no return value.
Hence, the option “B” is wrong.
d. Non-static:
Non-static variables can be accessed by any member variable.
Hence, the option “D” is wrong.
Want to see more full solutions like this?
Chapter 8 Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Additional Engineering Textbook Solutions
Starting out with Visual C# (4th Edition)
Starting Out with C++: Early Objects (9th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Computer Science: An Overview (12th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
- Build a class named car. This class is defined as follows: It has the fields: Car ID, Car model , Car make, Car color, Car year. Build a constructor that accepts the five parameters (Car ID, Car model , Car make,Car color, Car year). Override the method toString() to return the string representation of Car ID, Carmodel , Car make, Car color, Car year.arrow_forwardA(n) __________ is a method that appears in a base class but expects to be overridden in a derived class. a. abstract method b. virtual method c. concrete method d. base methodarrow_forwardWhen a class can be derived from another class and use its methods, this is called Polymorphism. A. True B. Falsearrow_forward
- Overloading is achieved when two or more methods in the same class have the same: return type parameter type method name method signaturesarrow_forwardThe __________ declares that a derived class is allowed to override a method. a. void keyword b. protected keyword c. base keyword d. virtual keywordarrow_forwardGiven the following code for a class named Employee, complete the following constructor public class Employee ( private int employeeID; private int SSN; public Emplyee(int employeeID, int SSN) {arrow_forward
- 2)Start by completing the constructor. The Sedan constructor takes only one argument (MPG) since the type will be “Sedan” for all Sedan objects. Write the efficient() method to return true if the MPG is greater than 30.0, false otherwise. Since the MPG are only stored in the superclass, you will need to access it using the getter method that is provided. starter Code Car.java: public class Car { private String type; private double mpg; public Car(String type, double mpg){ this.type = type; this. mpg = mpg; } public double getMPG(){ return mpg; } } Sedan.java: public class Sedan extends Car { public Sedan(double mpg){ // Complete the constructor with a call to the Superclass } public boolean efficient(){ // Enter your code here } } CarTester.java: public class CarTester { public static void main(String[] args) { Sedan clarity = new Sedan(52.7); Sedan bmw = new Sedan(22.6); System.out.println(clarity.efficient()); System.out.println(bmw.efficient()); } }arrow_forwardGiven the following class public class student { private String name; private String email; private int id; } Write two possible overloaded constructors for the class studentarrow_forwardHow many default constructors can a class have? a. A class cannot have a default constructor. b. only one c. as many as it needs d. one or more, but fewer than threearrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning