Topics Index

Method Declaration1687

If you need explanation Read this topic

If you need Answer Take test on this topic

Method Declaration1687
What is the output of the following program?
public class Krish {
    static char c = 70;
    public static void main(String[] args) {
        Krish krish = new Krish();
        System.out.print(c + " ");
    static void krish(char c) {
        int cr = c;
        cr = cr * 2;
        cr = cr + c - 20;
        c = (char) cr;

A. F 50
B. f 50
C. F f
D. F F
E. f f
F. 70 F
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.

D is the correct answer becuse the unicode value of 70 is F and in the krish function we are changing the value of local variable c but not static variable c

Posted by Harish Reddy Bitla    2013-08-16 08:39:26

ans shuld be D: aschii val of F is 70 n changes made in constructr will have local scope to c a it a formal parameter

Posted by Sarika Vollala    2013-08-16 08:39:43

Ans is d because first it will print F  since it's ASCII value is 70 and next after calling constructor c value is 190 it is not in ascii table (it is in extended ascii) it will print same as ans is d.

Posted by Anusha Moreddy    2013-08-16 08:54:03

Ans D since 70 is assigned to char variable its corresponding ASCII value F gets printed first...c is local (not a static)to krish function changes made to it are not reflected back so again F gets printed

Posted by Srinivas Nalla    2013-08-16 09:43:19

Congratulations Harish Reddy. You are this dose winner. Please send us your mobile details in a private message and we will process the recharge asap.

Posted by Merit Campus    2013-08-17 05:02:15

my details are 8125262251 tata docomo

Posted by Harish Reddy Bitla    2013-08-17 14:53:39

© meritcampus 2019

All Rights Reserved.

Open In App