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

What are the topics covered under core Java?
The major topics are listed below: 1. Java Basics - Variables, Data types, Operators, Control Statements,Strings, Arrays and Functions. 2. Object Oriented Concepts - Classes, Objects, Constructors, Inheritance,...
Sahil
0 0
6
Should we learn DBMS and RDBMS without any Java training?
java or i can say any programming language is not required to learn DBMS or RDBMS
Karthik
0 0
6
Java was developed in which year?
1995 By Sir James Gosling
Mohit
0 1
8
What are the best books to learn Java?
you can buy any book to learn java but for beginner's Herber Schild is prefer best
Prashant
0 0
6
What is a singleton class and when do you use it?
Singleton class have a private constructor. while we can't create an object from outside of class, we can create an object only once.
Prakash

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

Ask a Question

Related Lessons

How to create Rest web services in Java
Web services are web application components that lets two different applications to communicate over the network.Let if an application which in written java provides web services can be communicated through...

Object Oriented Programming Concepts :
Class : Class is user defined data type. Class is a logical representation of an Object. That means Class is used to define an object, how you want to create your software object. For Example...

Priority in TestNG
public class Priority { @Test (priority=1)public void login() {System.out.println("login");} @Testpublic void email1() {System.out.println("email1");} @Test (priority=-2)public void email2() {System.out.println("email2");} //I...
S

Sarthak C.

0 0
0

Overview on Auto IT and use in selenium webdriver
AutoIt v3 is a freeware BASIC-like scripting languages designed for automating the windows GUI and general scripting. It used a combination of simulated keystrokes, mouse movements and window/control manipulation...
S

Class and Objects in Java
Class is a template or a blueprint which is used to describe an object. On other hand Object is a reference of a class which follows all the stuff written inside the class. How about taking the whole tour in the following video

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