Giter VIP home page Giter VIP logo

breaking-inheritance's Introduction

Breaking-Inheritance

I kept getting some confusion regarding inheritance and the private-protected access in Java OOP. I tweaked here and there in this code to see how things play out.

What I have come to understand-

  • A java source file can't include more than one public class
  • The source file name and the class containing the main() must be the same
  • A public class and the source file that contains it, both must have the same name
  • If there are multiple main() in different classes, then the class with the same name as its source file will be the driving main()
  • Private properties can't be directly accessed outside its class, even with its own class object. It can only be directly accessed withing its class boundary
  • Any parent class type variable can hold its child class type object. But not vice versa. Suppose if A is parent class and B is child class -
    • A obj = new B() - is valid
    • B obj = new A() - is invalid
  • Here obj can only have access to the properties of A. It wouldn't have access to any property in B
  • If there is some method in B that overrides one in A, then when obj calls that method then the one in B is invoked
  • Child class has direct access to its parent class's protected properties; actually has access to all its non-private properties
  • Child class object will override parent class's attributes of the same name

Do correct me if I am wrong.

breaking-inheritance's People

Contributors

ashahrior avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.