Skip to main content

Posts

Showing posts from March, 2023

Runtime Polymorphism-Method Overriding in javaprogramming

 Runtime polymorphism will be implimented by the help of inheritance-Method Overriding method overriding Declaring a method in the subclass which already exists there in the parent class is known as method overriding.To override a method in a class, another method is created in its subclass that has the same signature(name,return type and parameter list) as the original method. Remember the following  point If the method is static, that method cannot be overridden If the method is declared in 'final' keyword that method cannot be overridden Importance of ‘ super’ keyword The super keyword is used to access immediate parent class(base class) properties If methods, variables and constructor are given the same name in the base class and the derived class, the base class property can be accessed using the super keyword.The super keyword should be used in the derived class only.Cannot be used in the main method Method overriding-sample program class Parent { void display()...

polymorphism and Overloading in java programming

 Overloading Concepts in java-polymorphism and Overloading in java programming  Overloading what is method overloading in java? The process of defining methods with the same name but different functionalities is called method overloading. In other words, with the same name and different parameters. This is not supported in c language. For example,an overloaded draw() method can be used to draw anything,such as a circle,square,triangle and so on. how many types of overloading in java? Types of overloading In java there are three types of overloading constructor overloading ---> Default constructor(without any arguments)Parameterized constructor(with some arguments) method overloading ---> Method Without any argument and method with arguments operator overloading ---> The + symbol  can be implemented in two ways one is  addition operator and another one is concatenation operator,same symbol used to perform two purposes.It is called operator overloading P...

java programming questions and answers for beginners-part1

  Java coding test questions and answers  Objective Type Q&A(part1) Array indexes start with?--> A: zero Which keyword is used to create a class in Java?--> A: class To declare an array in Java, define the variable type with? --> A: [ ] Which keyword is used to import a package from the Java API library?--> A: import Why include comments in Java programs?--> A: clarity of code Which keyword is used to return a value inside a method? --> A: return Which statement is used to stop a loop?--> A: break When does method overloading is determined?--> A: At compile time Which concept of Java is achieved by combining methods and attributes into a class?--> A: Encapsulation compile time polymorphism is one type of polymorphism in Java programming. Method overriding is a combination of inheritance and polymorphism? --> A: true The value of a string variable can be surrounded by single quotes --> A: false In Java, it is possible to inherit attribu...

Why Multiple and Hybrid Inheritances-Java Does not Support

    Why Multiple&Hybrid Inheritances-Java Doesn’t Support-How to solve it Multiple and Hybrid inheritance There are other two inheritance concepts multiple and hybrid inheritance.These are not directly supported in java.It is not possible for a child class to inherit two parent class properties through inheritance.In order to achieve this two techniques we have to implement interfaces concepts.This can be achieved through the interface concept,  called multiple inheritance.The combination of any two inheritance is called hybrid inheritance. multiple inheritance represantation Interface Interfaces,like abstract classes and methods,have a lot of functionality.Two keywords are used interface and implements .one of the differences between class and interface is that an interface cannot be instantiated,the keyword new can create only an instance of class. sample program-Interface Example program interface A { void show1(); } interface B { void show2(); } cl...