Skip to main content

four methods overload these methods

Write a program in java which has the following classes and methods: 
Class : OverloadDemo
Methods : test()
Declare four methods with the same name “test()” and overload these methods




class OverloadDemo{ 
public void test(){ 
System.out.println("It's a test method for null."); 
} 
public void test(int n){ 
System.out.println("It's a test method for displaying the int value "+n); 
} 
public void test(double d){ 
System.out.println("It's a test method for displaying the double value "+d); 
} 
public void test(String s){ 
System.out.println("It's a test method for displaying the String "+s); 
} 
} 
class overClass{ 
public static void main(String[] args) { 
OverloadDemo old = new OverloadDemo(); 
old.test(); 
old.test(12); 
old.test(25.35); 
old.test("Subham"); 
} 
}


OUTPUT:

It's a test method for null.
It's a test method for displaying the int value 12
It's a test method for displaying the double value 25.35
It's a test method for displaying the String Subham


Comments

Popular posts from this blog

Concurrency Control

What is Concurrency Control? Concurrency Control in Database Management System is a procedure of managing simultaneous operations without conflicting with each other. It ensures that Database transactions are performed concurrently and accurately to produce correct results without violating data integrity of the respective Database. Concurrent access is quite easy if all users are just reading data. There is no way they can interfere with one another. Though for any practical Database, it would have a mix of READ and WRITE operations and hence the concurrency is a challenge. DBMS Concurrency Control is used to address such conflicts, which mostly occur with a multi-user system. Therefore, Concurrency Control is the most important element for proper functioning of a Database Management System where two or more database transactions are executed simultaneously, which require access to the same data. Potential problems of Concurrency Here, are some issues which you will likely to face wh...

DBMS Keys

DBMS Keys KEYS in DBMS is an attribute or set of attributes which helps you to identify a row (tuple) uniquely in a relation(table). They allow you to find the relation between two tables. Keys help you uniquely identify a row in a table by a combination of one or more columns in that table. Key is also helpful for finding unique record or row from the table. Database key is also helpful for finding unique record or row from the table. Example: Employee ID FirstName LastName 11 Andrew Johnson 22 Tom Wood 33 Alex Hale In the above-given example, employee ID is a primary key because it uniquely identifies an employee record. In this table, no other employee can have the same employee ID. Here are some reasons for using sql key in the DBMS system. Keys help you to identify any row of data in a table. In a real-world application, a table could contain thousands of records. Moreover, the records could be duplicated. Keys in RDBMS ensure that you can uniquely identify a table record despite ...

Write a program to print the pyramid in Java

Write a program to print the following pyramid.      *     **   ****  ***** ****** import java.util.Scanner;  class pyramid{  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.println("Enter the range of the pyramid : ");  int n = sc.nextInt();  for(int i=1;i<=n;i++){  for(int j=1;j<=n-i;j++){  System.out.print(" ");  }  for(int k=1;k<=2*i-1;k++){  System.out.print("* ");  }  System.out.println();  }  sc.close();  }  } OUTPUT: Enter the range of the pyramid : 5      *     **   ****  ***** ******