What is not possible using java class Inheritance?

1. Private members of the superclass are not inherited by the subclass and can only be indirectly accessed.
2. Members that have default accessibility in the superclass are also not inherited by subclasses in other packages, as these members are only accessible by their simple names in subclasses within the same package as the superclass.
3. Since constructors and initializer blocks are not members of a class, they are not inherited by a subclass.
4. A subclass can extend only one superclass

class Vehicle
{
    // Instance fields
    int noOfTyres; // no of tyres
    private boolean accessories; // check if accessorees present or not
    protected String brand; // Brand of the car // Static fields
    private static int counter; // No of Vehicle objects created //
    Constructor Vehicle()
    {
        System.out.println("Constructor of the Super class called");
        noOfTyres = 5;
        accessories = true; brand = "X"; counter++;
     } // Instance methods
    public void switchOn()
    {
        accessories = true;
    }
    public void switchOff()
    {
        accessories = false;
    }
    public boolean isPresent()
    {
        return accessories;
    }
    private void getBrand()
    {
        System.out.println("Vehicle Brand: " + brand);
    } // Static methods
    public static void getNoOfVehicles()
    {
        System.out.println("Number of Vehicles: " + counter);
    }
}
class Car extends Vehicle
{
    private int carNo = 10;
    public void printCarInfo()
    {
        System.out.println("Car number: " + carNo);
        System.out.println("No of Tyres: " + noOfTyres); // Inherited. //
        System.out.println("accessories: " + accessories); // Not Inherited.
        System.out.println("accessories: " + isPresent()); // Inherited. //
        System.out.println("Brand: " + getBrand()); // Not Inherited.
        System.out.println("Brand: " + brand); // Inherited. //
        System.out.println("Counter: " + counter); // Not Inherited.
        getNoOfVehicles(); // Inherited.
     }
}
public class VehicleDetails
    {
         // (3)
         public static void main(String[] args)
        {
                new Car().printCarInfo();
        }
     }

 

Output:
Constructor of the Super class called
Car number: 10
No of Tyres: 5
accessories: true
Brand: X
Number of Vehicles: 1

11 comments:

sathya shri said...
This comment has been removed by the author.
Unknown said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

rpa training in chennai | rpa training in chennai
rpa training in pune | rpa online training | rpa training in bangalore

Mounika said...

Wonderful article, very useful and well explanation. Your post is extremely incredible. I will refer this to my candidates...
Python training in marathahalli | Python training institute in pune

Unknown said...

This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
Data Science training in rajaji nagar | Data Science with Python training in chenni
Data Science training in electronic city | Data Science training in USA
Data science training in pune | Data science training in kalyan nagar

Saro said...

A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.

rpa training in electronic-city | rpa training in btm | rpa training in marathahalli | rpa training in pune
blueprism training in chennai | blueprism training in bangalore | blueprism training in pune | blueprism online training

dwarakesh said...

Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

AWS Training in Bangalore | Amazon Web Services Training in bangalore , india
AWS Training in pune | Amazon Web Services Training in Pune, india
AWS Training in Chennai|Amazon Web Services Training in Chennai,India

aws online training and certification | amazon web services online training ,india

Suba said...

Big Thanks for this wonderful read. I enjoyed every little bit of reading and I have bookmarked your website to check out new stuff of your blog a must read blog.

Selenium Training in Chennai
Selenium Training
iOS Training in Chennai
French Classes in Chennai
Big Data Training in Chennai
French Classes in Chennai
French Courses in Chennai

vijaykumar said...





the blog is nicely maintain.when i read this blog i got lot of ideas and information.thanks to improve my knowledge.
RPA Training Institute in Chennai
RPA course in Chennai
Blue Prism Training Institute in Chennai
UiPath Training Institutes in Chennai

jefrin said...

This blog is very useful thanks for sharing

Best DevOps Training in Chennai

Raji said...

Hey Nice Blog !! Thanks For Sharing !!! Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging :)

Java Training in Chennai | Java Course in Chennai

subha said...

I am very happy to visit your blog. This is definitely helpful to me, eagerly waiting for more updates.thans a lot guys.
Ai & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More