Menu
Topics Index
...
`

Marks validation2639


If you need explanation Read this topic

If you need Answer Take test on this topic

Marks validation2639
What will be the output of the following program?
public class MarksValidation {
    public static void main(String[] args) throws Exception {
        int marks = 102;
        if (marks < 100) {
            System.out.println("You marks are Valid");
        } else {
            throw new MyException("You marks are not Valid");
        }
    }
}
class MyException extends Exception {
    public MyException(String string) {
        super(string);
        System.out.println(string);
    }
}

A. You marks are Valid
B. You marks are not Valid
C. Compilation Error
D. Runtime Error
Topic: User Defined Exception In Java

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.

Ans is D.. Run time error vl occur due to accessing the string variable from Exception class..

Posted by Om Prakash Om    2014-03-11 09:14:41


In the main() method of MarksValidation class, we have created an object of MyException class and passed a message. This message reaches the super class Exception from the constructor of MyException. Then the message is displayed. Then, MyException class object is thrown to the JVM. JVM receives the object, displays a message and terminates the program as we are not handling it. So, the answer is D.

Posted by Shaileshwar Sharma    2014-03-11 11:02:33


it prints Your marks are not valid bt along with dat a runtime exception is also found

Posted by Sai Abhishek    2014-03-11 13:37:40


Congratulations Shaileshwar Sharma. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-12 04:25:26


© meritcampus 2019

All Rights Reserved.

Open In App