Menu
Topics Index
...
`

Creating static and non static classes1760


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating static and non static classes1760
What will be the output of the following program?
public class InnerC {
    public static void main(String args[]) {
        InnerC q = new InnerC();
        q.myMethod();
        MyNest.main("Hello MeritCampus");
    }
    void myMethod() {
        System.out.println("Welcome to the JAVA world");
    }
    static class MyNest {
        public static void main(String st) {
            System.out.println(st);
        }
    }
}

A. Welcome to the JAVA world
Hello MeritCampus
B. Welcome to the JAVA world
C. Welcome to the JAVA world
Welcome to the JAVA world
Hello MeritCampus
D. Compilation Error or Runtime Error
Topic: Static and Non Static Variables - Static and Non Static Methods

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

A is the correct answer first we are calling myMethod which printd HelloMeritcamous followed by main of MyNest class

Posted by Ram Reddy Bitla    2013-09-11 03:42:01


A is the answer.since it first calls myMethod printing welcome to java and then passes hello merit campus to the main fucntion printing st content ie; hello merit campus

Posted by Shabaaz Shaikz    2013-09-11 03:51:38


A is the ans. first myMethod(),executed then after MyNest.main()

Posted by Rahul Roy    2013-09-11 04:16:49


ans is A:myMethod is called by creating an instance of same class InnerC which prints "Welcome to the JAVA world" then  main functiont is called by its class name MyNest without creating an instance because its a static method which prints "Hello MeritCampus" as passed in argument

Posted by Veda Sree    2013-09-11 06:05:11


Congratulations Ram Reddy Bitla. You are this dose winner. We will send the link using which you can claim your recharge.

Posted by Merit Campus    2013-09-12 03:43:12


© meritcampus 2019

All Rights Reserved.

Open In App