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

Senior Software Engineer with 12 years experience in 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

best source to learn java from?
Main source if information on Java is oracle documentation. But it takes your time to read through, a lot more than you expect. Better prefer a trainer who can give what you need.
Himanshu
How many classes are needed to teach advanced Java?
What Sachin and Vijay said is true. Number of classes can vary based on the prior knowledge of the student on computer concepts and programming. It also depends on how fast the student grasp/interact...
Kiran
0 0
8
Which is best to build web applications: PHP, Python, or Ruby? Why?
I have used almost all of the three language in my web working experience.PHP:It may be not that cool and I think it doesn't rely too much on the framework. Yes, PHP is just a language, but it is the only...
Sunil
0 0
7
Who can provide good Java training with real-time but not institute?
I provide industry specific training to students. If interested check my profile. I used to provide training in Big Data, Java, Scala and Spark too.
Sridevi
0 0
6
Is it possible to instantiate the abstract class?
Use anonymous class. Example: For an abstract class AbstrClass. AbstrClass ac = new AbstrClass() { public void m1() { // code...
Reshma

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 - Object Cloning
JAVA - Object Cloning Is the way of creating the same copy of object without calling the class constructor. It means we can make any class object multiple times without calling its default constructor....

Java Advantages
In this video, learn about Java and its advantages. Also, check out the difference between Java and C++, Java development kit, Java Run Time Environment (JRE) with a proper demonstration program for better clarity.

How can everyone prepare to clear any Java interview?
Java interview your java should be much strong then J2EE. core java and Advance java is the basic foundation for Interview. Some of the topic about which you should know before going for a java interview...

Class, Object and Methods in JAVA
Lesson-1: Class, Object and Methods of Java can be compared with body, heart and brain. Without these 3 things, Java does not exist. If you Google the above 3 items, you will find many definitions. But...

Java Achieve (JAR)
Java Archieve is a binary form to bundle a Java library which equivalent to zip file. It contains .class files, .properties, .jpeg, OR any supporting files to execute this library. For Example- junit.jar,...

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