Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Sunday, February 20, 2011
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
Answer: (b)
Character literals questions on java and answer with solution
Objective types questions and answers of character literals in java
(1)
public class Literal {
public static void main(String[] args) {
char b ='\n';
int a=(int)b;
System.out.println(a);
}
}
What will output when you compile and run the above code?
(a)10
(b)11
(c)12
(d) Compiler error
Answer: (a)
(2)
public class Literal {
(1)
public class Literal {
public static void main(String[] args) {
char b ='\n';
int a=(int)b;
System.out.println(a);
}
}
What will output when you compile and run the above code?
(a)10
(b)11
(c)12
(d) Compiler error
Answer: (a)
(2)
public class Literal {
String literal questions on java and answer with solution
Objective type
questions of string literals and answers in java programming
(1)
public class Literal {
public static void main(String[] args) {
String a="c:\\tc\\bin";
System.out.println(a);
}
}
What will output when you compile and run the above code?
(a) c:\\tc\\bin
(b) c:\tc\bin
(c) c: c\bin
(d) Compiler error
Answer: (b)
(2)
variables questions on java with explanation
Questions on variables in java with answers
(1)
public class Test {
public static void main(String[] args) {
int a=5;
{
Integer b=10;
}
int c=a+b;
System.out.println(c);
}
}
What will output when you compile and run the above code?
(a)15
(b)5
(c)Compiler error
(d) Run time error
Answer: (c)
Automatic type promotion questions on java and answer with solution
Java objective questions on automatic type promotion and answers
(1)
public class TypeConversion {
public static void main(String[] args) {
{
final int a='\15';
System.out.println(a);
}
int a=25;byte b=0100;
a=a+b;
System.out.println(a);
}
}
What will output when you compile and run the above code
java scjp questions and answers
Objective type questions for preparation of scjp exam and answers in java
(1)
public class Loop {
public static void main(String[] args){
for(int i=0;false;i++){
System.out.println("java");
}
}
}
What will be output of above program?
(a)java
(b) Null
(c)It will not print anything.
(d)Compiler error
Answer: (d)
(2)
java questions for beginners
Simple java objective type questions and answers for beginners
(1)
public class Loop {
public static void main(String[] args){
int i=1;
int j=5;
for(;;){
System.out.println(j>>>i);
}
}
}
What will be output of the above java program?
(a)2
1
(b)2
1
0
(c)Infinite loop
(d)Compiler error
Answer:
Bitwise operators questions in java
Bit wise operators objective type questions and answers
(1)
public class BitwiseOpe {
public static void main(String[] args) {
int a=010;
Integer b=10;
double d=~a|(b=a)<<2+b;
System.out.print(d);
}
}
What will output when you compile and run the above code?
(a)32768.0
(b)-9.0
(c)1.0
(d)Compiler error
Answer: (b)
Operators questions in java
Questions on operators in java questions and answers
(1)
public class BitwiseOpe {
public static void main(String[] args) {
int a=010;
Integer b=10;
double d=~a|(b=a)<<2+b;
System.out.print(d);
}
}
What will output when you compile and run the above code?
(a)32768.0
(b)-9.0
(c)1.0
(d)Compiler error
Answer: (b)
(2)
static keyword interview questions in java
Interview questions of static keyword in java and answers
(1)
class StaticDemo {
static int a=0;
int b=++a;
static int c=++a;
public static void main(String[] args){
System.out.print(c);
}
}
What will be output of above program?
(a)0
(b)1
(c)2
(d)Compiler error
Answer: (b)
(2)
class StaticDemo {
int a=0;
super java keyword questions and answers
Question on java keyword super and answers
(1)
class Square{
static double pi=Math.PI;
static void area(double r){
System.out.print((int)pi*r*r);
}
}
class Cube extends Square{
static void area(double r){
System.out.print(6*(int)pi*r*r);
}
}
class SuperDemo extends Cube{
public static void main(String[] args) {
abstract class questions in java
Objective type questions on abstract class in java and answers
(1)
abstract class Abstract {
public static void main(String[] args){
System.out.print("It is abstract class");
}
static{
System.out.println("Why");
}
}
What will output when you compile and run the above code?
(a) Why
It is abstract class
(b) It is
Example of interface in java
Objective type questions on interface in java and answers
(1)
interface Apple{
float cost=9.5f;
public void display();
}
class Try implements Apple{
public static void main(String[] args){
Try t=new Try();
t.display();
}
public void display(){
System.out.print("cost of apple is :"+cost);
}
}
What will output when
Questions on enum data type in java and answers
Questions on enum data type in java and answers
(1)
enum Barcode{
a,b,c,d,e;
}
public class EnumTest {
public static void main(String[] args) {
System.out.println(Barcode.b);
}
}
What will output when you compile and run the above java code?
(a)1
(b)2
(c)b
(d)Compiler error
Answer:(c)
(2)
enum Barcode{
a,b,c,d,e;
}
public
break and continue questions in java
break and continue keyword questions and answers in java
(1)
Which of the following jump statement is not supported by java?
(a) break
(b) goto
(c) continue
(d) return
Answer: (b)
(2)
public class BreakDemo {
public static void main(String[] args){
int j=1;
for(int i=1;i<5;i++){
j*=i;{
break;
}
How to reverse a number in java
Java code to reverse a given number
import java.io.*;
class Test {
public static void main(String[] args) throws IOException {
int num,sum=0,r;
System.out.println("Enter a number");
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
num=Integer.parseInt(br.readLine());
while(num!=
GCD of two numbers in java
Java code to to find GCD or Greatest common divisor of two numbers
import java.io.*;
class Test {
public static void main(String[] args) throws IOException {
int n1,n2;
System.out.println("Enter first number:");
BufferedReader br1=new BufferedReader(new InputStreamReader (System.in));
n1=Integer.parseInt(br1.readLine());
System.out.println("Enter
Program to find fibonacci series in java
Java code to print Fibonacci series
import java.io.*;
class Test {
public static void main(String[] args) throws IOException {
int i=0,j=1,k=2,r,f;
System.out.println("Enter the range:");
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
r=Integer.parseInt(br.readLine());
System.out.println("FIBONACCI SERIES: ");
Binary to decimal conversion in java
Java code to covert binary number to decimal number
import java.io.*;
class Test {
public static void main(String[] args) throws IOException {
long no,n=0l,j=1,rem,no1;
System.out.println("Enter the binary number");
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
no=Long.parseLong(br.readLine());
no1=no;
Saturday, February 19, 2011
Perfect number program in java
Java code to check given number is perfect number or not
import java.io.*;
class Test {
public static void main(String[] args) throws IOException {
int n,i=1,sum=0;
System.out.println("Enter a number:-");
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
n=Integer.parseInt(br.readLine());
while(i>0){
Subscribe to:
Comments (Atom)