## INDEX

### java questions for viva

Java questions and answers for viva

(1)

public class Literal {
public static void main(String[] args) {
String str\$="world";
char str_='X';
String \$_=str\$+str_;
System.out.print(\$_);

}
}

What will output when you compile and run the above code?

(a)world
(b)worldX
(c)world’X’
(d)Compiler error

Explanation:

In java programming language operator + can add two numeric data type as well as it can concatenate two string or character data type.
Here \$_=”world”+’X’ ,Operator + is working as concatenating one string and char data type.
Note: \$_ is valid variable name. In java programming language variable name includes alphabet, digits few special characters like underscore (_), dollar singe (\$) but it should not be any reserved word of java language.
Integer Literals

(2)

public class Literal {
public static void main(String[] args) {
int a=012;
int c=a*2;
System.out.print(c);

}
}

What will output when you compile and run the above code?

(a) 24
(b) 024
(c) 20
(d) Compiler error

(3)

public class Literal {
public static void main(String[] args) {
byte a=0110;
int c=a*2;
System.out.print(c);

}
}

What will output when you compile and run the above code?

(a)1100
(b)220
(c)144
(d) Java doesn’t support binary number.Compiler error

(4)

public class Literal {
public static void main(String[] args) {
byte a=08;
int c=a>>2;
System.out.print(c);

}
}

What will output when you compile and run the above code?

(a)32
(b)2
(c)02
(d) Compiler error

(5)

public class Literal {
public static void main(String[] args) {
byte a=0x11;
byte b=0X22;
int c=a&&b;
System.out.print(c);

}
}

What will output when you compile and run the above code?

(a)2
(b)0
(c)1
(d) Compiler error

(6) Numerical value of false in java is :

(a)  0
(b) All values except one
(c) zero and all negative integers
(d) java doesn’t support any numerical value of false

(7)

public class Literal {
public static void main(String[] args) {
boolean b =5==5;
int a=(int)b;
System.out.println(a);
}
}

What will output when you compile and run the above code?

(a)0
(b)1
(c)NaN
(d) Compiler error

(8) Which of the following is not valid java floating point literal?

(a) 4.5f
(b) .033D
(c) 5.0e^2
(d) 6.8

(9) Which of the following is a not valid java floating point literal?

(e) 8.09F
(f) .033f
(g) 5.0E25
(h) 6.8e^2

(10)

public class Scope {
public static void main(String[] args) {
int a=5;
{
a=10;
int b=15;
a=a+b;
}
System.out.println(a);
}
}

What will output when you compile and run the above code?

(a)5
(b)25
(c)Run time exception
(d) Compiler error

(11)

public class Scope {
public static void main(String[] args) {
{
static int a=5;
}
{
int a=10;
a=++a;
}
System.out.println(a);
}
}

What will output when you compile and run the above code?

(a)5
(b)21
(c)11
(d) Compiler error

(12)

public class Scope {
public static void main(String[] args) {
{
int a=5;
System.out.println(a);
}
int a=6;
a=~a;
System.out.println(a);
}
}

What will output when you compile and run the above code?

(a)5
-7
(b)5
-6
(c)Run time exception
(d) Compiler error
{"ft_lang_label":"__label__en","ft_lang_prob":0.5126928,"math_prob":0.8817035,"size":3809,"snap":"2022-40-2023-06","text_gpt3_token_len":1100,"char_repetition_ratio":0.15032852,"word_repetition_ratio":0.42857143,"special_character_ratio":0.31609347,"punctuation_ratio":0.14408867,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9748968,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-09-30T15:50:02Z\",\"WARC-Record-ID\":\"<urn:uuid:81cf679c-5ab1-4fbf-96d8-b0ed2c59891a>\",\"Content-Length\":\"110439\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b6b486d4-aab8-46b0-98db-ad5d4397e0bf>\",\"WARC-Concurrent-To\":\"<urn:uuid:d3997ced-e75d-40fd-9d18-988c9e99e248>\",\"WARC-IP-Address\":\"142.251.111.121\",\"WARC-Target-URI\":\"https://www.cquestions.com/2009/01/literals-questions-on-java-and-answer.html\",\"WARC-Payload-Digest\":\"sha1:MK6BDWOLIXL5SOCUPAP25LFXIDS5AQGF\",\"WARC-Block-Digest\":\"sha1:GR7SG4DESEV3BKYYHO7JP25YSYJFHCHJ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030335491.4_warc_CC-MAIN-20220930145518-20220930175518-00752.warc.gz\"}"}