Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: hey! i am facing this issue "The field Parent.buffalo is not visible"

  1. #1
    Junior Member
    Join Date
    Sep 2024
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hey! i am facing this issue "The field Parent.buffalo is not visible"

    before putting my code what i expect from my code, i wan to know that "if i create a new class in same package in which there are already exist an inherited class. and i want to know that whether i can access those protected field directly from this class, because there are a saying that protected field can be accessed in same package."
    Total i created 3 classes and 2 package.
    let me clarify that i am doing this all on eclipse ide.

     
    package first;
    public class Parent {
        protected int buffalo = 5; // Protected field
    }
     
    package second;
    import first.Parent;
    public class ChildClass extends Parent {
        public static void main(String[] args) {
            ChildClass a = new ChildClass();
            a.buffalo = 10;  // Accessing protected field from subclass
            System.out.println(a.buffalo); // Should print 10
        }
    }  // this child class work fine! 
     
     
    package second;
    public class Abhi {
        public static void main(String[] args) {
            ChildClass ob = new ChildClass();
            ob.buffalo = 20;  // i want to access this, here the problem occur
            System.out.println(ob.buffalo);  // and also here 
        }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,098
    Thanks
    65
    Thanked 2,716 Times in 2,666 Posts

    Default Re: hey! i am facing this issue "The field Parent.buffalo is not visible"

    Try asking here: https://www.coderanch.com/forums
    That site has more experts on this kind of problem.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: August 3rd, 2014, 10:44 PM
  2. Replies: 2
    Last Post: May 22nd, 2014, 01:17 PM
  3. parent/child jsp and "opener" in jsp
    By nisha jaiswal in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: July 29th, 2013, 06:28 AM
  4. Replies: 3
    Last Post: July 3rd, 2013, 08:25 AM
  5. Error message "Type result cannot be resolved or is not a field"
    By asreall in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 28th, 2012, 08:40 AM