UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Base obj=new Child(); What are the advantage and real life application of above code?

Asked by Last Modified  

25 Answers

Learn Java

Follow 1
Answer

Please enter your answer

Java Trainer

Have you ever observed while communicating with databases? You can find such type of example while writing code from communicating with DB. Connection connectionObject = DriverManager.getConnection(); or Statement simpleStatement = connectionObject.getStatement(); The value of the connectionObject...
read more
Have you ever observed while communicating with databases? You can find such type of example while writing code from communicating with DB. Connection connectionObject = DriverManager.getConnection(); or Statement simpleStatement = connectionObject.getStatement(); The value of the connectionObject variable depends on the database driver you are using (most of the time you load the driver with Class.forName("some driver implementaion")). The answer for your question is, such type of coding helps you to implement and use your own mechanism that suits to your requirements / circumstances. read less
Comments

Tutor

1.It is basis of Polymorphism. 2. Lets say you have a parent class called Animal and child classes called Dog, Cat, and Lizard. Each class has a method call makeSound(). Then when you say Animal a1 = new Dog(); and Animal a2 = new Cat(), a1.makeSound() will bark and a2.makeSound() will meow. The...
read more
1.It is basis of Polymorphism. 2. Lets say you have a parent class called Animal and child classes called Dog, Cat, and Lizard. Each class has a method call makeSound(). Then when you say Animal a1 = new Dog(); and Animal a2 = new Cat(), a1.makeSound() will bark and a2.makeSound() will meow. The technical term for this behavior is called polymorphism. It is useful for code reuse. You only need to write code once for an application that has Animals makeSound() when they are happy, instead of separate code for each animal type. 3.Another use of polymorphism is hiding your code's implementation from other users. For example you can show other users that you are using a List and then you have the choice to implement the List as a LinkedList or as an ArrayList. You can also choose a LinkedList and then at a later time switch to an ArrayList without effecting your users. You also can't say Dog d = new Animal() because a Dog is an Animal but an Animal is not necessarily a Dog. read less
Comments

Industry expert and professional lecturer/trainer

Dynamic Polymorphism which promotes calling only those methods which parent is aware of. Mostly used in API creation.
Comments

You can get all the attributes and behavior of a class by creating its object.
Comments

Best Training institute for Both Technical and Non Technical domians

This is the most fundamental use of polymorphism because using a parent class reference to refer to a child object is what allows you to take advantage of the benefits of polymorphism. Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs...
read more
This is the most fundamental use of polymorphism because using a parent class reference to refer to a child object is what allows you to take advantage of the benefits of polymorphism. Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. read less
Comments

Software Professional Trainer with 26+ years of Experience in Software Design and Development

It dynamic polymorphism, where derived class object is assigned to Base class object. Whenever you want to do late binding you can use this concept.
Comments

Software Professional with 14 years experience - Mentoring & Training Students & Professionals

Polymorphishm is the advantage of the above code. Say you have animal class with animal reference you can create object of a cat or a dog. So in run time it differentiates. For example Animal a = new Cat(); (if cat extends animal) a = new Dog()(if dog extends animal) so same reference a can hold objects...
read more
Polymorphishm is the advantage of the above code. Say you have animal class with animal reference you can create object of a cat or a dog. So in run time it differentiates. For example Animal a = new Cat(); (if cat extends animal) a = new Dog()(if dog extends animal) so same reference a can hold objects of cat and dog as both inherites animal read less
Comments

Let's simplify Coding, It's a great Fun.

Hi, The above code is using the parent reference type to point to child object. Now from the obj reference you can point to all the members of base class as well as to the child class (by type casting). This is the normal practice in java technologies to create the parent reference type for child...
read more
Hi, The above code is using the parent reference type to point to child object. Now from the obj reference you can point to all the members of base class as well as to the child class (by type casting). This is the normal practice in java technologies to create the parent reference type for child objects, this strategy enables your code flexible for any sub-child, for example, if you have a method like this add(Collection c), this means parameter can be object of List,Set or any sub-collection object, this makes your method more generic & powerful. regards vijay read less
Comments

This is the basis for polymorphism: Imagine you have several child classes that inherit from you parent class. You want to use all these child classes through the interface / methods defined on your parent class, without worrying about the implementation details in each child class (each might do something...
read more
This is the basis for polymorphism: Imagine you have several child classes that inherit from you parent class. You want to use all these child classes through the interface / methods defined on your parent class, without worrying about the implementation details in each child class (each might do something different, but with the same overall semantics). This is possible because the child class has a IS A relationship with its parent class since child inherits from parent. read less
Comments

Java/J2EE/SFDC Corporate Trainer

This is actually dynamic binding, depending upon demand the memory will be created for respective object.
Comments

View 23 more Answers

Related Questions

Hi, Can anyone help me on below queries? 1. What makes a class as "Thread safe class" ? 2. equals() method uses 3. Difference between String vs StringBuffer ?
There are three ways to construct thread-safe Java class which has some state: 1. Make it truly immutable 2.Make field volatile. 3.Use a synchronized block
Saurav
Who invented Java language?
James Gosling. You could have google it!!
Niranjan
What is the difference between a C program execution and a Java program execution?
When we compile C program then it convert into exe file ie Machine language with the help of OS lib file which is platform dependent . If we compile java prgram then it convert into class file with the...
Kaushal
0 0
5
What is a good foundation course for JAVA?
I will not prefer any programming language or technology instead, You can focus on Concept and Principles. Because when you say your a programmer you should be a programmer rather than saying Java programmer,...
Rajeev J

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

JAVA OOPs Concepts (Object-Oriented Programming System)
JAVA OOPs Concepts (Object-Oriented Programming System) It is primarily having below crucial points. Without below essential points, we will never be able to achieve OOPs in java, PHP, C#, etc. Now let...

ClassNotFoundException vs NoClassDefFoundError
ClassNotFoundException NoClassDefFoundError It is an exception and happens due to programmer’s mistake and can be recovered by updating the code. Thrown when an application tries...

Write your first Python program in 10 minutes
1. Download python from python official site search "python download" in google 2. Install in your machine 3. verify using : "python --version" command 4. Write first program using notepad create...

Introduction to Course Content
Video about what we are going to learn throughout the Java Training Session .

Advance Java
1) Servlet • Basics of Servlet • Servlet Request • Servlet Collaboration • Servlet Config • Servlet Context • Attribute • Session Tracking • Event and Listener •...
A

Recommended Articles

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more