Understanding the combination of inheritance, packages and access modifiers

I am working on a problem to help my practical understanding of accessing inherited members and methods from a different package using both inheritance and instance variable.
Unfortunately, I am totally lost when I tried to set this up and understand what was happening.
Problem:
Create a class named "classA" under package "pack1" with 4 members (int pub_a, int priv_a, int prot_a, int def_a) and methods (pub_func1, priv_func1, prot_func1, def_func1). Mark the members and methods with 4 different access specifiers (public, private, protected, and default)
Create a class named "classB" under package "pack2", ClassB will inherit classA of package pack1. ClassB will have 2 members (int pub_b, int priv_b) and methods (pub_func2, prot_func2) with 2 different access specifiers (public, protected)
Try accessing the members of class classA in package pack1 inside class classB of package pack2. Find out what members and methods are accessible and not-accessible through inheritance.
Create an instance of class classA inside class classB of package pack2. Find out what members and methods are accessible and not-accessible through the instance.
Note: In your solution, comment out the lines that are in-accessible with the actual error message at the top of the comment.
So I produced the following code (I don't think i set this up right):
//filename A.java
package pack1;
public class A {
     public int pub_a;
     private int priv_a;
     protected int prot_a;
     int def_a;
     public int pub_func1() {return 1;}
     private int priv_func1() {return 2;}
     protected int prot_func1() {return 3;}
     int def_func1() {return 4;}
//filename B.java
package pack2;
import pack1.A;
public class B extends A{
     public     int pub_b;
     private int priv_b;
     public int pub_func2() { return 5; }
     private int priv_func2() { return 6; }
     //directly inherited fields, at least one should be accessible?
     pub_a = 1;
     priv_a = 1;
     prot_a = 1;
     def_a = 1;
     int i;
     // directly inherited methods, at least one should be accessible?
     i = pub_func1();
     i = priv_func2();
     A a = new A();
     //not sure what's accessible here, as no error red underlines appear
     a.pub_a = 1;
     a.priv_a = 1;
     a.prot_a = 1;
     a.def_a = 1;     
}I would be interested to know how one would approach and address this problem.

//filename B.java
package pack2;
import pack1.A;
public class B extends A{
     public     int pub_b;
     private int priv_b;
     public int pub_func2() { return 5; }
     private int priv_func2() { return 6; }
     //directly inherited fields, at least one should be accessible?
     pub_a = 1;//true
     priv_a = 1;// false
     prot_a = 1;//true
     def_a = 1;//false
     int i;
     // directly inherited methods, at least one should be accessible?
     i = pub_func1();//true
     i = priv_func2();//false
     A a = new A();
     //not sure what's accessible here, as no error red underlines appear
     a.pub_a = 1;//true
     a.priv_a = 1;//false
     a.prot_a = 1//false;
     a.def_a = 1;//false
}Edited by: fun_with_me on May 31, 2008 8:30 AM

Similar Messages

  • Creation of developement class,package and access key

    COULD ANYBODY EXPLAIN about
    creation of developement class,package and access key
    and who will create them?

    Working With Development Objects
    Any component of an application program that is stored as a separate unit in the R/3 Repository is called a development object or a Repository Object. In the SAP System, all development objects that logically belong together are assigned to the same development class.
    Object Lists
    In the Object Navigator, development objects are displayed in object lists, which contain all of the elements in a development class, a program, global class, or function group.
    Object lists show not only a hierarchical overview of the development objects in a category, but also tell you how the objects are related to each other. The Object Navigator displays object lists as a tree.
    The topmost node of an object list is the development class. From here, you can navigate right down to the lowest hierarchical level of objects. If you select an object from the tree structure that itself describes an object list, the system displays just the new object list.
    For example:
    Selecting an Object List in the Object Navigator
    To select development objects, you use a selection list in the Object Navigator. This contains the following categories:
    Category
    Meaning
    Application hierarchy
    A list of all of the development classes in the SAP System. This list is arranged hierarchically by application components, component codes, and the development classes belonging to them
    Development class
    A list of all of the objects in the development class
    Program
    A list of all of the components in an ABAP program
    Function group
    A list of all of the function modules and their components that are defined within a function group
    Class
    A list of all of the components of a global class. It also lists the superclasses of the class, and all of the inherited and redefined methods of the current class.
    Internet service
    A list of all of the componentse of an Internet service:
    Service description, themes, language resources, HTML templates and MIME objects.
    When you choose an Internet service from the tree display, the Web Application Builder is started.
    See also Integrating Internet Services.
    Local objects
    A list of all of the local private objects of a user.
    Objects in this list belong to development class $TMP and are not transported. You can display both your own local private objects and those of other users. Local objects are used mostly for testing. If you want to transport a local object, you must assign it to another development class. For further information, refer to Changing Development Classes
    http://help.sap.com/saphelp_46c/helpdata/en/d1/80194b454211d189710000e8322d00/content.htm
    Creating the Main Package
    Use
    The main package is primarily a container for development objects that belong together, in that they share the same system, transport layer, and customer delivery status. However, you must store development objects in sub-packages, not in the main package itself.
    Several main packages can be grouped together to form a structure package.
    Prerequisites
    You have the authorization for the activity L0 (All Functions) using the S_DEVELOP authorization object.
    Procedure
    You create each normal package in a similar procedure to the one described below. It can then be included as a sub-package in a main package.
    To create a main package:
    1.       Open the Package Builder initial screen (SE21 or SPACKAGE).
    2.       In the Package field, enter a name for the package that complies with the tool’s Naming Conventions
    Within SAP itself, the name must begin with a letter from A to S, or from U to X.
    3.       Choose Create.
    The system displays the Create Package dialog box.
    4.       Enter the following package attributes:
    Short Text
    Application Component
    From the component hierarchy of the SAP system, choose the abbreviation for the application component to which you want to assign the new package.
    Software component
    Select an entry. The software component describes a set of development objects that can only be delivered in a single unit. You should assign all the sub-packages of the main package to this software component.
    Exception: Sub-packages that will not be delivered to customers must be assigned to the HOMEsoftware component.
    Main Package
    This checkbox appears only if you have the appropriate authorization (see Prerequisites).
    To indicate that the package is a main package, check this box.
    5.       Choose  Save.
    6.       In the dialog box that appears, assign a transport request.
    Result
    The Change package screen displays the attributes of the new package. To display the object list for the package in the Object Navigator as well, choose  from the button bar.
    You have created your main package and can now define a structure within it. Generally, you will continue by adding sub-packages to the main package. They themselves will contain the package elements you have assigned.
    See also
    Adding Sub-Packages to the Main Package
    http://help.sap.com/saphelp_nw04/helpdata/en/ea/c05d8cf01011d3964000a0c94260a5/content.htm
    access key used for change standard program.
    www.sap.service.com

  • I'm trying to understand the difference between Photoshop Elements and Lightroom software.

    Does one have things the other does not?

    Hi,
    Lightroom is to manage photos and produce derivative images without ever modifying an original file. Its processing functionality has a narrow feature-set covering the most common needs of professional photographers whereas Elements is a simpler yet powerful photo manipulation tool. Elements is designed to satisfy the needs of photo enthusiasts who like to manipulate images.
    You can also go through the thread to understand the basic difference between PSE and Lightroom.
    Check if this helps.
    Thanks,
    Swapnil

  • The combination of artwork size and resolution exceeds the maximum that can be rasterized.

    hi there, im rajesh M S Aaryan, Creative agent @ SmartDesignstudios. which i founded.
    here is my Solution for above  Question
    Created File by giving 48 Inches (Hieght) * 240 inches (width) in Illustrator after Complete design, i just tried Export it to .Tif Format but error Occurred  "the combination of artwork size and resolution exceeds the maximum that can be rasterized".
    Answer: Save the file as EPS format and open in Photoshop do no alter anything finally save as .Tif Format
    this actually works

    yes we can create
    try to Export into .tiff format"
    you'll get this error
    the combination of artwork size and resolution exceeds the maximum that can be rasterized.

  • What is the difference between access specifiers and access modifiers?

    what is the difference between access specifiers and access modifiers? are they same? if not what is the difference.

    Access Specifier are used to specifiy how the member variable ,methods or class to other classes.They are public ,private and protected.
    Access Modifier:
    1.Access
    2.Non Access
    Access:
    public ,private,protected and default.
    Non Access:
    abstract,final,native,static,synchronized,transient,volatile and strictfp

  • Default/package/none access modifier

    Hi,
    I was hoping for some discussion on the default/package/none access modifier. It's always really bugged me that we have public, private, protected, and then "none", while it seems to me that it would be less confusing, and more consistent to use the keyword "package", or maybe even "default".
    Then, source code would look like
    public class MyClass{
        public int getValue() {}
        private void setValue() {}
        protected void someMethod() {}
        package int justForPackage() {}
    }I know this concept has come up before, but the books I've read which mention this topic haven't offered any actaul justification/explanation for why there isn't some keyword.
    Anyway, are there any insights as to why java is this way, and any reasons why java should or shouldn't be changed to include the package access modifier.

    A good example is within a tightly grouped package (usually should be this way) you may have some cooperative classes that access methods.
    // one .java file
    public class SomeHelper {
       private void method() {
         new ClassForUsers().accessHiddenLogic();
    // next .java file in same package
    public ClassForUsers {
        /* default-access */ void accessHiddenLogic() {
    }But, you may want to allow users to subclass your ClassForUsers, without giving them access to the hidden logic method directly:
    // another .java file in a different package
    public class UsersSubclass extends ClassForUsers {
        public void userMethod() {
            // can't do this
            accessHiddenLogic();
    }This could be for either business logic or security reasons. So, package level access can be very useful. However, I've seen that in practice it is avoided because it isn't obvious what is going on.

  • What is the difference beween idoc package and idoc collection

    Hi friends,
        i am unable to understand difference betwen Idoc package and Idoc cillection.
        Please give me clear clarification.
    Thanks and regards
    Bhanu

    Hi Bhanu,
    Apart from the replies above, in case you're looking for an answer from ECC perspective, here are some inputs: (ECC is considered as sender here)
    1. IDoc Collection:
       This will collect the IDocs and will not immediately send it to the target system after they are created. Program RSEOUT00 can be later scheduled for these collected IDocs to deliver them to the target. You can treat this as a park and process approach which proves useful in several business scenarios.
    This standard link gives more insight:
    SAP Library - IDoc Interface/ALE
    2. IDoc Packaging:
        This defines the number of IDocs to be packed and sent in 1 RFC call (tRFC). If you set is as 20, then 20 IDocs will be sent in 1 tRFC request. This doesn't connote whether the IDocs will be triggered immediately or later, this just talks about the bundling of IDocs per RFC call.
    Hope this helps.
    Regards,
    Abhishek

  • Understanding the correct use of FromOrderComponets and ToOrderComponents

    Hi all
    Someone could help me understand the difference, and in what case I must use fromOrderComponets and in what case i must use toOrderComponents.
    In the Decomposition Rules.
    I've done multiple orchestrations to own cartridges, by multiple products, and I've never needed to use the expression toOrderComponents, because we've always used FromOrdercomponents.
    any explanation is helpful,
    Best Regards
    David A Leon H

    Hi Leon,
    In the Design Studio Help, please refer to "Working with Decomposition Rules" inorder to understand Decomposition Rules.
    Property Correlation is used while setting a dependency in the Product Specification. This is where FromOrderComponent & ToOrderComponent both are extensively used. For more information, please refer help section for the following.
    1)About Order Item Dependencies
    2)Orchestration Dependency Editor Order Item Dependencies Tab
    Thanks,
    Naveen Jabade

  • How can I see the combined result of primary and secondary color correction in the vectorscope

    Hello there,
    so I can't figure out how to see the combined result of all the color correction I did on a shot. If I click on each individual layer (primary or each individual secondary) I can see the result of each one individually on the vectorscope, but I want to be able to see the final result of all the layers combined.  Is this possible within speedgrade? 
    thanks in advance for the help
    Luc

    Occasionally SpeedGrade seems to forget itself or something. It's kinda weird/funny, but ... on occasions I have been working and say one tab just stopped responding when I clicked on it, but everything else was fine. Shut it down, come back into it ... all is righteous. Thankfully I've not had some of the major bonkers-responses some clearly have. I'm sure that will come also. This is an incredibly complicated and complex program under the hood, of course. But all in all ... I do love working in it.
    When I have the excuse to do so ...

  • Acces specifiers and Access Modifiers in java

    what are Access specifiers?
    what are Access modifiers?
    Whether both of them are same or is there any difference?

    As far as I know "access specifier" == "access modifier".
    To me, they both mean "the Java Language word which specifies the visibility of a class or class attribute".
    http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html
    ... but I'm no expert.
    Cheers.

  • Overriding and Access Modifier

    Is it must to override with the same access modifiers ?
    For example
    class A {
    protected void test() {
    class B extends A {
    //overrides test() here
    }

    RZP wrote:
    Is it must to override with the same access modifiers ?No, but an overridden method cannot have more restrictive access modifiers, so
    public String getName();cannot be overridden by
    protected String getName();However, the other way around is fine.
    Winston

  • Problem in package and accessing classes in the same directory

    i have a class JApplet1 which calls other classes from the same directory.ALL the other classes have a main within them whereas JApplet1 has an init method within it...the problem is this JApplet1 class is not able to call the other classes. there r no compile time errors but at runtime the classes are not being called...what should i do....suggestions plz..

    What exception are you getting?

  • How to install the adobe creative cloud packager and how to apply the adobe ID for Admin user

    Hi team,
    Anyone has done install silently the captivate 8 using AAME? i try using this tool to create the msi but its not work.
    i saw the previous disussion on captivate 7 and they said cannot use AAME and need to use CCP.
    isit also applicable to Adobe Captivate 8? if yes cana anyone tell  me how to download the CCP?
    I already create my Adobe ID but when i try to login, its stated "Adobe does not recognize you as an authorized user of this web site."
    How can i access this site? appreciate your help

    The help I have been using (unsuccessfully) is here:
    >These links provide additional guidance for deployment support
    >Creative Cloud Packager Help: http://helpx.adobe.com/creative-cloud/packager.html
    Dave

  • Packaging and accessing resources in a JAR

    I'm working on an application and I would like to package my resources (icons, about dialog images, splash screen images, release version text, etc.) in the jar file I'm going to distribute for deployment.  I would like to access these resources from the JAR file in my deployed code.  But I would also like them accessible when I'm running the code in my Eclipse IDE.  Is there a way to do this using only one code base?
    My Eclipse project structure is src (folder) which contains my source code, bin (folder) which contains my class files and res (folder) which contains my resource files.
    I am using the javapackager utility to create my deployment JAR and build a self-contained deployment .exe for deploying to Windows.
    Is there a way to have the javapackager build a single JAR file from multiple sources (i.e. my bin and res folders)?  What do I have to do in my code so that the same code can be used to load resources when I'm running in Eclipse and the self-contained deployment?
    Thanks,
    Mike

    The Java Tutorials has several trails for loading resources.
    Retrieving Resources (The Java™ Tutorials >                    Deployment > Java Web Start)
    Use the getResource method to read resources from a JAR file. For example, the following code retrieves images from a JAR file.
    // Get current classloader
    ClassLoader cl = this.getClass().getClassLoader();
    // Create icons
    Icon saveIcon  = new ImageIcon(cl.getResource("images/save.gif"));
    Icon cutIcon   = new ImageIcon(cl.getResource("images/cut.gif"));
    The example assumes that the following entries exist in the application's JAR file:
    •images/save.gif
    •images/cut.gif
    See that last sentence?
    You put what you need in the jar file and then use the 'getResource' methods to load them.

  • Using the DBMS_LDAP PL/SQL package to access OID images

    Hey,
    I have built a script using LDAP to access the OID information for all the Portal users and store that information in a regular table in my database, but I am having some trouble retrieving the images associated with each user, so I was wondering if someone could help me out with a code example or point me in the right direction in how I could do this.
    Thanks

    I am seaching for a similar solution. Any ideas please?

Maybe you are looking for

  • IBase : CRM_IBASE_COMP_CREATE

    Hello, I am currently creating a new interface between our AS/400 legacy system and crm 2007. To do that, i am using the following fm like CRM_IBASE_INITIALIZE, CRM_IBASE_CREATE, etc.. The problem is that i need to add a component into an exisiting i

  • No audio from clips

    I just downloaded the Trial version of Adobe Premiere Pro CS5 and when I import a clip, i'm not getting any audio, not even anything showing up in the 'Audio Master Meter' I do get audio when I import a .mp3 file HELP pleeease, this is very irritatin

  • Registry settings changed for burning cds

    I got the iTunes Assistant message that said the registry setting used by the iTunes drives for importing and burning CD's and DVD's are wrong. I suggested that I reinstall iTunes, so I did. However, I am still getting the same message and can't figu

  • Custom item field in POWL

    Hi all, I've added an item custom field in POWL following this steps: - Add the field to structure /SAPSRM/S_SEARCHFIELDS. (with the same name that it have in st. INCL_EEW_PD_ITEM_CSF_CTR ) - Add the field in view /SAPSRM/V_SRC_CR. - Add the field in

  • Open class that has an *.txt in it in a browser

    Hello, We have a problem, we want to open a class file from a webpage, but in the class there is an txt file needed. In the appletviewer it works, but now i want it to let it work in a browser, and than i get an Security Error. Does someone knows a s