Question Index

Write a program to get the method signature, given the object and the method name.

Input (Object, String) Output (String)
new A(), div double div(double, double)
new A(), mul int mul(int, int, int)
new B(), getName java.lang.String getName()
new B(), getFirstName java.lang.String getFirstName(java.lang.String)
new B(), mergeStrings void mergeStrings(java.lang.String, java.lang.String)
new C(), distance float distance(float, float, float)
new C(), isValid boolean isValid(boolean)
new D(), relation java.lang.String relation(java.lang.String, java.lang.String)
new D(), run null

class GetMethodSignature

{    public static void main(String s[])
        A a = new A();
        System.out.print("The method signature of div in class A is : " + getMethodSignature(a, "div"));


public static String getMethodSignature(Object object, String methodName) {
String result = null;
//Write code here to get the method signature
class A {

A() {

public void add(int a, int b) {

public int mul(int a, int b, int c) {
return 5;

public double div(double a, double b) {
return 2.5;

class B extends A {

B() {

public String getName() {
return "Cerone";

public String getFirstName(String fullName) {
return "MC";

public void mergeStrings(String a, String b) {

class C {

C() {

public float distance(float c, float d, float e) {
return 1.2f;

public boolean isFound() {
return true;

public boolean isValid(boolean k) {
return false;

class D extends B {

D() {

D(int a, int c) {

public void speed(int time, int distance) {

public String relation(String person1, String person2) {
return "brother";



Topic: Java Regular Expression

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App