While studying method overriding, a few rules also became clear that control how overriding works in Java. These rules ensure that the behaviour of inherited methods stays consistent across parent and child classes. Things that became clear : • the method name and parameter list must remain the same • the return type must be the same or related to the parent method • the access level of the method cannot be reduced in the child class • private methods do not participate in inheritance and therefore cannot be overridden • methods declared as final cannot be overridden • if a method is abstract in the parent class, the child class must provide its implementation These rules help Java maintain a predictable structure when classes inherit behaviour from one another. Understanding these restrictions made it easier to see how inheritance and polymorphism work together in object oriented programs. #java #oop #programming #learning #dsajourney
Lakhyadeep Sen’s Post
More Relevant Posts
-
Another form of polymorphism in Java appears through method overriding. This happens when a child class provides its own implementation of a method that already exists in the parent class. Things that became clear : • method overriding occurs during inheritance • the child class keeps the same method name and parameters as the parent class • the implementation of the method is changed in the child class • the method that runs is decided at runtime • this is known as runtime polymorphism A simple example shows how this works : class Parent { void show() { System.out.println("Parent method"); } } class Child extends Parent { void show() { System.out.println("Child method"); } } When an object of the child class is used, the child’s version of the method is executed. This mechanism allows subclasses to adjust behaviour while still keeping the structure defined by the parent class. #java #oop #programming #learning #dsajourney
To view or add a comment, sign in
-
🛫 Deep Dive: Mastering Encapsulation in Java! if you're diving into Object-Oriented Programming, Encapsulation is a non-negotiable pillar. it's all about security-protecting the "internal state" of your object from unauthorized interfaces. Here's the 2-step blueprint : 🔒 1. Restrict Direct Access Declare your data member as a private. Think of it like a private rooms in your home-they aren't accessible to the general public outside the gate. 🚪 2. Provide Controlled Access Use public getter and setters. These act like a secure main gate, allowing you to validate and control exactly how data enters or leaves your class. ⭐ Key Takeaways ✔️ Solve "Shadowing" : When parameter names match instance variables, the local variable "Shadows" the class variable. Use this keyword to tell Java exactly which one to update. ✔️ The Golden Rule of Getters: You can update multiple variables in one setter, but a getter can only return one value. if you have 5 variables , you need to create 5 individual getters! Harshit T TAP Academy #Java #OOPS #Encapsulation #LearnToCode #TapAcademy #Pillar #SoftwareEnginnering #security #CodingJourney
To view or add a comment, sign in
-
-
🛫 Deep Dive: Mastering Encapsulation in Java! if you're diving into Object-Oriented Programming, Encapsulation is a non-negotiable pillar. it's all about security-protecting the "internal state" of your object from unauthorized interfaces. Here's the 2-step blueprint : 🔒 1. Restrict Direct Access Declare your data member as a private. Think of it like a private rooms in your home-they aren't accessible to the general public outside the gate. 🚪 2. Provide Controlled Access Use public getter and setters. These act like a secure main gate, allowing you to validate and control exactly how data enters or leaves your class. ⭐ Key Takeaways ✔️ Solve "Shadowing" : When parameter names match instance variables, the local variable "Shadows" the class variable. Use this keyword to tell Java exactly which one to update. ✔️ The Golden Rule of Getters: You can update multiple variables in one setter, but a getter can only return one value. if you have 5 variables , you need to create 5 individual getters! Harshit T TAP Academy #Java #OOPS #Encapsulation #LearnToCode #TapAcademy #Pillar #SoftwareEnginnering #security #CodingJourney
To view or add a comment, sign in
-
-
Day 4 of Learning Java : Today I started my journey into Java programming which is taught by Aditya Tandon Sir. Here are the key concepts I learned today: How Java Stores Negative And Floating Numbers? 1. Storing Negative Integers: Two’s Complement -- >Java doesn't just stick a "minus sign" in front of a number. Instead, it uses a system called Two’s Complement. In a standard 32-bit int, the most significant bit is the sign bit. • 0: Positive •1: Negative ∆ How to calculate Two's Complement: -->To store a negative number (like -5), Java follows these steps: 1.Start with the positive binary: 00000101 (for 5). 2.Invert the bits (One's Complement): 11111010. 3.Add 1: 11111011. 2. Storing Floating-Point Numbers: IEEE For float and double, Java follows the IEEE 754 standard. It stores numbers in a way similar to scientific notation but in binary. ∆ A 32-bit float is broken into three parts: 1.Sign Bit (1 bit): 0 for positive, 1 for negative. 2.Exponent (8 bits): Determines how large or small the number is (the "scale"). 3.Mantissa/Fraction (23 bits): Stores the actual digits of the number. This is just the beginning. Excited to continue this journey Special thanks to Rohit Negi bhaiya & Aditya Tandon Sir. #Day4 #Java #Coding #Learning #Consistency
To view or add a comment, sign in
-
-
🚀 Day 5/45 – Mastering Loops in Java On Day 5 of my Java learning journey, I explored one of the most important concepts in programming — Loops. Loops allow us to execute a block of code multiple times, which is essential for solving real-world problems efficiently. 📚 What I Learned Today Today I learned about: ✔ for loop for controlled iterations ✔ while loop for condition-based execution ✔ do-while loop which executes at least once These concepts helped me understand how repetition works in programming. 💻 Practice Work To apply my learning, I implemented: • Printing numbers from 1 to 10 • Calculating the sum of first 10 numbers • Generating multiplication tables • Creating star patterns using nested loops 🎯 Key Takeaway Loops are extremely powerful and help reduce repetitive code. Understanding loops is essential for solving complex problems and building efficient programs. Daily practice is helping me improve my logical thinking. #Java #Programming #LearningInPublic #CodingJourney #SoftwareDevelopment #Consistency
To view or add a comment, sign in
-
Day 1 of Learning Java : Today I started my journey into Java programming which is taught by Aditya Tandon Sir. Here are the key concepts I learned today: One question is that: If C and C++ were already existing.. why was Java even needed? The answer is :- •C/C++ compile directly into machine code. •It is platform dependent. •Change the processor or OS to Recompile code. But Java? •java Bytecode → JVM Machine Code •Platform Independent. •Same bytecode. •Different JVMs. •Runs everywhere. That's WORA: Write Once, Run Anywhere. •No messy pointer manipulation •Automatic memory management This is just the beginning. Excited to continue this journey Special thanks to Rohit Negi bhaiya & Aditya Tandon Sir. #Java #Coding #Learning #Consistency
To view or add a comment, sign in
-
-
🚀 Day 13/45 – Understanding Encapsulation in Java On Day 13 of my Java learning journey, I explored one of the core principles of Object-Oriented Programming — Encapsulation. Encapsulation is all about protecting data and controlling access to it using methods. 📚 What I Learned Today Today I learned: ✔ What encapsulation is and why it is important ✔ How to make variables private for data security ✔ Using getter and setter methods to access data ✔ Real-world analogy of data hiding 💻 Practice Work To apply my learning, I implemented: • A simple program using private variables and getter/setter methods • A bank balance example to demonstrate controlled access 🎯 Key Takeaway Encapsulation helps in building secure and maintainable applications by restricting direct access to data. It is a fundamental concept that improves code quality and structure. Step by step, I am getting closer to understanding core Java concepts. #Java #Programming #LearningInPublic #CodingJourney #SoftwareDevelopment #OOP
To view or add a comment, sign in
-
🚀 Day 73/100 of My Java Programming Series ☕💻 Today, I learned and practiced Method Overloading in Java — an important concept of compile-time polymorphism. 📌 What I explored today: ✅ What is Method Overloading ✅ Same method name with different parameters ✅ Changing number of arguments ✅ Changing data types of arguments ✅ Improving code readability and reusability ✅ Real-time examples for better understanding 💡 Key takeaway:Method Overloading allows us to define multiple methods with the same name but with different parameter lists. It helps make programs more flexible, organized, and easier to understand. 🧠 This concept is very useful in writing cleaner code and understanding how Java supports polymorphism. 🔥 Day 73 completed. Still learning, still growing! #Java #JavaProgramming #OOP #MethodOverloading #Polymorphism #100DaysOfCode #CodingJourney #Programming #SoftwareDevelopment #JavaDeveloper #LearningJourney10000 Coders Meghana M
To view or add a comment, sign in
-
Inheritance is one of the core ideas in object oriented programming that allows a class to reuse the properties and behaviour of another class. Instead of rewriting the same logic again, a new class can extend an existing one. Things that became clear : • inheritance allows one class to acquire the properties and methods of another class • the class that provides the features is called the parent or base class • the class that inherits those features is called the child or derived class • the extends keyword is used to create this relationship in Java • it helps promote code reuse and cleaner program structure A simple example helps illustrate the idea : class Person { String name; int age; } class Student extends Person { int marks; } In this case the Student class automatically gets the name and age properties from the Person class while also adding its own data. This structure helps avoid repeating code and keeps related behaviour organized through class relationships. #java #oop #programming #learning #dsajourney
To view or add a comment, sign in
-
🚀 Java Learning Journey – Day 5 Why Java Says "No" to Multiple Inheritance (and "Yes" to Interfaces) 💎 Ever wondered why Java doesn't allow a class to inherit from two parents? It all comes down to the Diamond Problem. When two parent classes have the same method, the compiler gets confused: "Which one should I use?" To keep things clean and prevent bugs, Java blocks this at the class level. But wait—you can still achieve the same goal! 💡 By using Interfaces, you get the flexibility of multiple inheritance without the ambiguity. Check out this quick visual guide I put together to break it down. 👇 #Java #Programming #ObjectOrientedProgramming #SoftwareDevelopment #CodingTips #TechCommunity
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development