Skip to main content

Posts

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...

Abstraction In Java Programming Short Explanation

 ABSTRACT CLASS AND ABSTRACT  METHOD IN JAVA  What is abstraction in java? Showing only  essential parts and  hiding the implementation part. This is called abstraction.This can be achieved by  java programming. Ex:-- while download  android application in playstore we get only .exe file.when running this exe file the software will work but we cannot see the implementation part.This type of application can be done by java programming,this technique is called abstraction or data hiding Abstract class and abstract method abstract class and abstract method in java with example We know that abstraction is a pillar of the oops concepts,and abstraction is showing only essential parts and hiding implementation details.The class contains variables, methods and constructors.So if any class consists of at least one abstract method then the class will be called an abstract class. The abstract class and abstract method is created using the abstract keyword.An ab...

Hierarchical Inheritance In Java with Example Program

  Hierarchical Inheritance In Java with Example Program Hierarchical Inheritance Inheritance which contain only one parent class and multiple child class, and all child class directly extends the parent class this is called hierarchical inheritance For example, consider A, B and C as three classes: A parent class,B and C are two child classes.Here B & C extends to A class,Similarly object should be created separately for B & C class.So B&A class property can be accessed using B class object. C&A class property can be accessed using C class object. Hierarchical Inheritance in java example program Program class Parent { int age1=50; void display1() { System.out.println("This is parent class method disply1"); System.out.println("Parent class accessing through both obj1 and obj2"); System.out.println("____________________________________"); } } class Bchild extends Parent { int age2=40; void display2() { System.out.print...

Multilevel Inheritance In Java with Example program

  Multilevel  Inheritance In Java With Example Programs Multilevel Inheritance In single inheritance we have only one parent class and one child class but multilevel inheritance the child class again have subclasses.This technique is called multilevel inheritance For example, if A, B and C are three classes, we can inherit class B to class A and class C to class B using extends keyword. Also, if we create a C class object, we can access the properties of all three classes. We can limit the object creation in inheritance. This is the advantage of inheritance. Java multilevel inheritance example program class A { int age1=50; void display1() { System.out.println("This is parent class method disply1"); System.out.println("parent class also known as base class"); System.out.println("Another name super class "); } } class B extends A { int age2=40; void display2() { System.out.println("This is child class method disply2"); Sy...

How to run java simple program using notepad

 Java simple program using notepade and cmd-Based on java basic notes 1  Java hello world program class Hello1{ public static void main(String arg[]){        System.out.println("Hello World");     }       } 2 Java program to create a string variable class StringExample {   public static void main(String[] args)  {     String line1 = "Hello world"; String line2 = "welcome to java programming";     System.out.println(line1+'\n'+line2);   } } 3 Java program to print both small and capital alphabets class Alphabets {       public static void main(String args[]){             char ch;             System.out.println("Small Alphabets: "); System.out.println("----------------");             for( ch = 'a' ; ch <= 'z' ; ch++ ){                System.out.p...

Inheritance-Java oops concepts-Single Inheritance

single inheritance in java with example programs  Inheritance Inheritance means one class acquiring the properties of another class this can be also called as parent child, that means child class acquire the properties(accessing variables and methods) of parent class. Parent class also known as super class(or base class) and child class known as sub class(or derived class) Implementing inheritance concept we will use the extends keyword Single inheritance  single inheritance in java program with output Single inheritance means only one base class and one derived class. Java single inheritance Sample program single inheritance in java example program   class Main1 { public static void main(String args[]) { ChildExample obj=new ChildExample(); obj.display(); System.out.println("Age is :"+obj.age); obj.display1(); System.out.println("Age is :"+obj.age1); } }   class ParentExample { int age=60; void display() {   Sys...