0

Base class:

public class BaseClass
{
    public void beforeClass
    {
        TestDataLoader loader = new TestDataLoader(); //some implementation here
        readData = loader.fetchdata(...);
    }
}

Class-1:

public class ClassA extends BaseClass
{ 
  String a;
  public void method1()
  { 
    ..
    ..
  } 
}

Class-2:

public class ClassB extends classA
{
   String a1; 
   public void methodB(ClassA classA1)
   {
       if(classA1 == null) 
       {
           //do nothing
       }   
   classA1.method1();
   }
}

The problem i see here is that i am not able use testDataLoader (for which the implementation is in BaseClass) of ClassA in my ClassB. I am able to access method1 of ClassA in my ClassB but i am not able to use the testDataLoader of ClassA in ClassB

Note: i cannot pass arguments to method1 of ClassA as it won't support arguments to be passed to it.

Could someone help me on this?

user1023627
  • 183
  • 1
  • 3
  • 12
  • 2
    In `ClassA` instead of `TestDataLoader loader = new TestDataLoader();` delcare it as **`protected`** `TestDataLoader loader = new TestDataLoader();` – lealceldeiro Oct 25 '19 at 09:29
  • Possible duplicate of [What is the difference between public, protected, package-private and private in Java?](https://stackoverflow.com/questions/215497/what-is-the-difference-between-public-protected-package-private-and-private-in) – lealceldeiro Oct 25 '19 at 09:30
  • Sorry corrected my code. Sorry for the confusion earlier. and one more thing - i won't be able to make any changes in ClassA or BaseClass as those are being used by others. – user1023627 Oct 25 '19 at 09:38
  • In that case keep all your classes in same package then. – Atul Oct 25 '19 at 09:53
  • @Atul - that is not possible. as the classes are in different packages. The intention here is to re-use the method of ClassA instead of duplicating the code again in ClassB – user1023627 Oct 25 '19 at 09:57
  • even though i extend BaseClass to my ClassB .. I am not able to use the testDataLoader in my ClassB i.e., public class ClassB extends BaseClass – user1023627 Oct 25 '19 at 10:07
  • any update please let me know – user1023627 Oct 25 '19 at 11:23

0 Answers0