Bird
0
0

Which of the following is the correct way to declare a Base Page class constructor that accepts a WebDriver instance?

easy📝 Syntax Q3 of 15
Selenium Java - Page Object Model
Which of the following is the correct way to declare a Base Page class constructor that accepts a WebDriver instance?
Apublic BasePage() { WebDriver driver; }
Bpublic BasePage(WebDriver driver) { this.driver = driver; }
Cpublic void BasePage(WebDriver driver) { this.driver = driver; }
DBasePage(WebDriver driver) { driver = this.driver; }
Step-by-Step Solution
Solution:
  1. Step 1: Understand constructor syntax in Java

    A constructor has no return type and matches the class name exactly.
  2. Step 2: Check parameter assignment correctness

    Assigning this.driver = driver correctly sets the instance variable.
  3. Final Answer:

    public BasePage(WebDriver driver) { this.driver = driver; } -> Option B
  4. Quick Check:

    Constructor syntax = No return type, assign driver [OK]
Quick Trick: Constructor has no return type and assigns driver [OK]
Common Mistakes:
  • Adding void return type to constructor
  • Incorrect assignment order
  • Declaring driver inside constructor without class scope

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes