SlideShare a Scribd company logo
Language Fundamentals
      Duration 1 Hr.
Question 1
An object is




Select 1 correct option.
a what classes are instantiated from.

b an instance of a class.

c a blueprint for creating concrete realization of abstractions.

d a reference to an attribute.

e a variable.


Ans: b
Question 2
What will the following code snippet print?

int index = 1;
 String[] strArr = new String[5];
 String myStr = strArr[index];
 System.out.println(myStr);




Select 1 correct option.
A It will print nothing.
B It will print 'null'
C It will throw ArrayIndexOutOfBounds at runtime.
D It will print NullPointerException at runtime.
E None of the above.


Ans: b
Question 3
In which of these variable declarations, will the variable remain uninitialized
unless explicitly initialized?




Select 1 correct option.
a Declaration of an instance variable of type int.
b Declaration of a static class variable of type float.
c Declaration of a local variable of type float.
d Declaration of a static class variable of class Object
e Declaration of an instance variable of class Object.




Ans: c
Question 4
What is the range of a 'char' data type?




Select 1 correct option.
a 0 - 65, 535
b 0 - 65, 536
c -32,768 - 32,767
d 0 - 32,767
e None of the above




Ans: a
Question 5
What will the following program print?

public class TestClass
{
  public static void main(String[] args)
  {
    unsigned byte b = 0;
    b--;
    System.out.println(b);
  }
}


Select 1 correct option.
A0
B -1
C 255
D -128
E It will not compile.
Ans: e unsigned
Question 6
Carefully examine the following code.

public class StaticTest
{
  static
  { System.out.println("In static"); }
  { System.out.println("In non - static"); }
  public static void main(String args[ ])
  {
     StaticTest st1;             //1
     System.out.println(" 1 ");
     st1 = new StaticTest();         //2
     System.out.println(" 2 ");
     StaticTest st2 = new StaticTest(); //3
  }
}
What will be the output?

Select 1 correct option.
a In static, 1, In non - static, 2, In non - static : in that order.
b Compilation error.
c 1, In static, In non - static, 2, In non - static : in that order.
d In static, 1, In non - static, 2, In non - static : in unknown order.
e None of the above.
Ans: a
Question 7
What will happen when you compile and run the following program using the
command line:
java TestClass 1 2

public class TestClass
{
          public static void main(String[] args)
          {
                    int i = Integer.parseInt(args[1]);
                    System.out.println(args[i]);
          }
}

Select 1 correct option.
a It'll print 1
b It'll print 2
c It'll print some junk value.
d It'll throw ArrayIndexOutOfBoundsException
e It'll throw NumberFormatException

Ans: d
Question 8
Which of the following are valid at line 1?

public class X
{
          line 1: //put statement here.
}




Select 2 correct options
a String s;
b String s = 'asdf';
c String s = 'a';
d String s = this.toString();
e String s = asdf;


Ans: a&d
Question 9
A method is ..


Select 1 correct option.
a an implementation of an abstraction.
b an attribute defining the property of a particular abstraction.
c a category of objects.
d an operation defining the behavior for a particular abstraction.
e a blueprint for making operations.




Ans: d
Question 10
An instance member ...




Select 2 correct options
a can be a variable, constant or a method.
b is a variable or a constant.
c Belongs to the class.
d Belongs to an instance of the class.
e is same as a local variable.




Ans: a&d
Question 11
Given the following class, which of these given blocks can be inserted at line
1 without errors?

public class InitClass
{
    private static int loop = 15 ;
    static final int INTERVAL = 10 ;
    boolean flag ;
    //line 1
}

Select 4 correct options
a static {System.out.println("Static"); }
b static { loop = 1; }
c static { loop += INTERVAL; }
d static { INTERVAL = 10; }
e { flag = true; loop = 0; }


Ans: a,b,c,e
Question 12
Which of the following are correct ways to initialize the static variables MAX and CLASS_GUID ?

class Widget
{
  static int MAX; //1
  static final String CLASS_GUID; // 2
  Widget()
  {
     //3
  }
  Widget(int k)
  {
     //4
  }
}

Select 2 correct options
a Modify lines //1 and //2 as : static int MAX = 111; static final String CLASS_GUID = "XYZ123";
b Add the following line just after //2 : static { MAX = 111; CLASS_GUID = "XYZ123"; }
c Add the following line just before //1 : { MAX = 111; CLASS_GUID = "XYZ123"; }
d Add the following line at //3 as well as //4 : MAX = 111; CLASS_GUID = "XYZ123";
e Only option 3 is valid.


Ans: a,b
Question 13
What will be the result of attempting to compile and run the following class?

public class TestClass
{
  public static void main(String args[ ] )
  {
    int i = 1;
    int[] iArr = {1};
    incr(i) ;
    incr(iArr) ;
    System.out.println( "i = " + i + " iArr[0] = " + iArr [ 0 ] ) ;
  }
  public static void incr(int n ) { n++ ; }
  public static void incr(int[ ] n ) { n [ 0 ]++ ; }
}

Select 1 correct option.
a The code will print i = 1 iArr[0] = 1;
b The code will print i = 1 iArr[0] = 2;
c The code will print i = 2 iArr[0] = 1;
d The code will print i = 2 iArr[0] = 2;
e The code will not compile.

Ans: b
Question 14
Consider the following code snippet ...

boolean[] b1 = new boolean[2];
boolean[] b2 = {true , false};
System.out.println( "" + (b1[0] == b2[0]) + ", "+ (b1[1] == b2[1]) );

What will it print ?

Select 1 correct option.
a It will not compile.
b It will throw ArrayIndexOutOfBoundsError at Runtime.
c It will print false, true.
d It will print true, false.
e It will print false, false.




Ans: c
Question 15
What will the following program print?

public class TestClass
{
  static String str;
  public static void main(String[] args)
  {
    System.out.println(str);
  }
}


Select 1 correct option.
a It will not compile.
b It will compile but throw an exception at runtime.
c It will print 'null'
d It will print nothing.
e None of the above.


Ans: c
Question 16

public class TestClass
{
  public static void main(String[] args)
  {
    String tom = args[0];
    String dick = args[1];
    String harry = args[2];
  }
}
What will the value of 'harry' if the program is run from the command
line:
java TestClass 111 222 333

Select 1 correct option.
a 111
b 222
c 333
d It will throw an ArrayIndexOutOfBoundsException
e None of the above.

Ans: c
Question 17
Which of these are keywords in Java?




Select 3 correct options
a default
b NULL
c String
d throws
e long




Ans: a,d,e
Question 18
Which of the following are valid identifiers?


Select 2 correct options
a class
b $value$
c angstrom
d 2much
e zer@




Ans: b,c
Question 19

public class TestClass
{
  public static void main(String[] args)
  {
    String str = "111";
    boolean[] bA = new boolean[1];
    if( bA[0] ) str = "222";
    System.out.println(str);
  }
}
What will the above program print?

Select 1 correct option.
a 111
b 222
c It will not compile as bA[0] is uninitialized.
d It will throw an exception at runtime.
e None of the above.


Ans: a
Question 20
What will be the output of the following lines ?

System.out.println("" +5 + 6);    //1
System.out.println(5 + "" +6);     // 2
System.out.println(5 + 6 +"");     // 3
System.out.println(5 + 6);       // 4

Select 1 correct option.
a 56, 56, 11, 11
b 11, 56, 11, 11
c 56, 56, 56, 11
d 56, 56, 56, 56
e 56, 56, 11, 56




Ans: a
Question 21
Which of the following is not a primitive data value in Java?




Select 2 correct options
a "x"
b 'x'
c 10.2F
d Object
e false




Ans: a,d
Question 22
What does the zeroth element of the string array passed to the standard main
method contain?




Select 1 correct option.
a The name of the class.
b The string "java".
c The number of arguments.
d The first argument of the argument list, if present.
e None of the above.




Ans: d
Question 23
What will the following program print?

public class TestClass
{
            static boolean b;
            static int[] ia = new int[1];
            static char ch;
            static boolean[] ba = new boolean[1];
            public static void main(String args[]) throws Exception
            {
                           boolean x = false;
                           if( b )
                           {
                                       x = ( ch == ia[ch]);
                           }
                           else x = ( ba[ch] = b );
                           System.out.println(x+" "+ba[ch]);
            }
}

Select 1 correct option.
a true true
b true false
c false true
d false false
e It'll not compile.

Ans: d
Question 24
What will be the result of attempting to compile and run the following code?

public class InitClass
{
  public static void main(String args[ ] )
  {
     InitClass obj = new InitClass(5);
  }
  int m;
  static int i1 = 5;
  static int i2 ;
  int j = 100;
  int x;
  public InitClass(int m)
  {
     System.out.println(i1 + " " + i2 + " " + x + " " + j + " " + m);
  }
  { j = 30; i2 = 40; } // Instance Initializer
  static { i1++; }     // Static Initializer
}

Select 1 correct option.
a The code will fail to compile, since the instance initializer tries to assign a value to a static member.
b The code will fail to compile, since the member variable x will be uninitialized when it is used.
c The code will compile without error and will print 6, 40, 0, 30, 5 when run.
d The code will compile without error and will print 5, 0, 0, 100, 5 when run.
e The code will compile without error and will print 5, 40, 0, 30, 0 when run.




Ans: c
Question 25
Which code fragments will print the last argument given on the command line to the standard output, and exit without any output and
exceptions if no arguments are given?

1.
 public static void main(String args[ ])
 {
       if (args.length != 0) System.out.println(args[args.length-1]);
 }
2.
public static void main(String args[ ])
{
       try {     System.out.println(args[args.length-1]);   }
       catch (ArrayIndexOutOfBoundsException e) { }
}
3.
 public static void main(String args[ ])
 {
     int i = args.length;
     if (i != 0) System.out.println(args[i-1]);
}
4.
public static void main(String args[ ])
{
    int i = args.length-1;
   if (i > 0) System.out.println(args[i]);
}
5.
 public static void main(String args[ ])
 {
       try { System.out.println(args[args.length-1]); }
       catch (NullPointerException e) {}
 }

Select 3 correct options
a Code No. 1
b Code No. 2
c Code No. 3
d Code No. 4
e Code No. 5


Ans: a,b,c
Question 26
Consider the following class:

public class ArgsPrinter
{
            public static void main(String args)
            {
                         for(int i=0; i<3; i++)
                         {
                                       System.out.println(args);
                         }
            }
}
What will be printed when the above class is run using the following command line:
java ArgsPrinter 1 2 3 4


Select 1 correct option.
a123
b ArgsPrinter 1 2
c java ArgsPrinter 1 2
d111
e None of these.




Ans: e
Question 27
Consider the following class definition:

public class TestClass
{
  public static void main(){ new TestClass().sayHello(); } //1
  public static void sayHello(){ System.out.println("Static Hello World"); } //2
  public void sayHello() { System.out.println("Hello World "); } //3
}

What will be the result of compiling and running the class?

Select 1 correct option.
a It will print 'Hello World'.
b It will print 'Static Hello World'.
c Compilation error at line 2.
d Compilation error at line 3.
e Runtime Error.




Ans: b
Question 28
What will the following program print?

public class TestClass
{
  static int someInt = 10;
  public static void changeIt(int a)
  {
    a = 20;
  }
  public static void main(String[] args)
  {
    changeIt(someInt);
    System.out.println(someInt);
  }
}

Select 1 correct option.
a 10
b 20
c It will not compile.
d It will throw an exception at runtime.
e None of the above.

Ans: a
Question 29
What is the numerical range of short data type?


Select 1 correct option.
a It depends on the platform the JVM is running.
b 0 to 65535
c -32768 to 32767
d 0 to 32767
e -16384 to 16383




Ans: c

More Related Content

What's hot

Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
mehul patel
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paperfntsofttech
 
SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8
Chaitanya Ganoo
 
Core java
Core javaCore java
Core java
prabhatjon
 
12. Exception Handling
12. Exception Handling 12. Exception Handling
12. Exception Handling
Intro C# Book
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
Dror Helper
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
Danairat Thanabodithammachari
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
Upender Upr
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
Mike Dirolf
 
Simulado java se 7 programmer
Simulado java se 7 programmerSimulado java se 7 programmer
Simulado java se 7 programmer
Miguel Vilaca
 
Java programs
Java programsJava programs
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
Knowledge Center Computer
 
E5
E5E5
E5
lksoo
 
Inheritance and-polymorphism
Inheritance and-polymorphismInheritance and-polymorphism
Inheritance and-polymorphism
Usama Malik
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
raksharao
 
Part - 2 Cpp programming Solved MCQ
Part - 2  Cpp programming Solved MCQ Part - 2  Cpp programming Solved MCQ
Part - 2 Cpp programming Solved MCQ
Knowledge Center Computer
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
Intro C# Book
 
conditional statements
conditional statementsconditional statements
conditional statements
James Brotsos
 

What's hot (20)

Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8
 
Core java
Core javaCore java
Core java
 
12. Exception Handling
12. Exception Handling 12. Exception Handling
12. Exception Handling
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
 
Loop
LoopLoop
Loop
 
Simulado java se 7 programmer
Simulado java se 7 programmerSimulado java se 7 programmer
Simulado java se 7 programmer
 
Java programs
Java programsJava programs
Java programs
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
 
E5
E5E5
E5
 
Inheritance and-polymorphism
Inheritance and-polymorphismInheritance and-polymorphism
Inheritance and-polymorphism
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
 
Part - 2 Cpp programming Solved MCQ
Part - 2  Cpp programming Solved MCQ Part - 2  Cpp programming Solved MCQ
Part - 2 Cpp programming Solved MCQ
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
conditional statements
conditional statementsconditional statements
conditional statements
 

Similar to Java language fundamentals

Java Quiz
Java QuizJava Quiz
Java Quiz
Dharmraj Sharma
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
krtioplal
 
Scjp questions
Scjp questionsScjp questions
Scjp questionsroudhran
 
ExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docx
gitagrimston
 
sample_midterm.pdf
sample_midterm.pdfsample_midterm.pdf
sample_midterm.pdf
EFRENlazarte2
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
mayorothenguyenhob69
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
CodeOps Technologies LLP
 
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdfAll based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
aroraenterprisesmbd
 
2 object orientation-copy
2 object orientation-copy2 object orientation-copy
2 object orientation-copyJoel Campos
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
rosemarybdodson23141
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
praveensomesh
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional
Isabella789
 
Java concepts and questions
Java concepts and questionsJava concepts and questions
Java concepts and questionsFarag Zakaria
 
Exceptional exceptions
Exceptional exceptionsExceptional exceptions
Exceptional exceptions
Llewellyn Falco
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
Sujata Regoti
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
Chhom Karath
 
Question 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docxQuestion 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docx
amrit47
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
ShashikantSathe3
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
Rumman Ansari
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
Shohan Ahmed
 

Similar to Java language fundamentals (20)

Java Quiz
Java QuizJava Quiz
Java Quiz
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
Scjp questions
Scjp questionsScjp questions
Scjp questions
 
ExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docx
 
sample_midterm.pdf
sample_midterm.pdfsample_midterm.pdf
sample_midterm.pdf
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdfAll based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
 
2 object orientation-copy
2 object orientation-copy2 object orientation-copy
2 object orientation-copy
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional
 
Java concepts and questions
Java concepts and questionsJava concepts and questions
Java concepts and questions
 
Exceptional exceptions
Exceptional exceptionsExceptional exceptions
Exceptional exceptions
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Question 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docxQuestion 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docx
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 

Recently uploaded

MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 

Java language fundamentals

  • 1. Language Fundamentals Duration 1 Hr.
  • 2. Question 1 An object is Select 1 correct option. a what classes are instantiated from. b an instance of a class. c a blueprint for creating concrete realization of abstractions. d a reference to an attribute. e a variable. Ans: b
  • 3. Question 2 What will the following code snippet print? int index = 1; String[] strArr = new String[5]; String myStr = strArr[index]; System.out.println(myStr); Select 1 correct option. A It will print nothing. B It will print 'null' C It will throw ArrayIndexOutOfBounds at runtime. D It will print NullPointerException at runtime. E None of the above. Ans: b
  • 4. Question 3 In which of these variable declarations, will the variable remain uninitialized unless explicitly initialized? Select 1 correct option. a Declaration of an instance variable of type int. b Declaration of a static class variable of type float. c Declaration of a local variable of type float. d Declaration of a static class variable of class Object e Declaration of an instance variable of class Object. Ans: c
  • 5. Question 4 What is the range of a 'char' data type? Select 1 correct option. a 0 - 65, 535 b 0 - 65, 536 c -32,768 - 32,767 d 0 - 32,767 e None of the above Ans: a
  • 6. Question 5 What will the following program print? public class TestClass { public static void main(String[] args) { unsigned byte b = 0; b--; System.out.println(b); } } Select 1 correct option. A0 B -1 C 255 D -128 E It will not compile. Ans: e unsigned
  • 7. Question 6 Carefully examine the following code. public class StaticTest { static { System.out.println("In static"); } { System.out.println("In non - static"); } public static void main(String args[ ]) { StaticTest st1; //1 System.out.println(" 1 "); st1 = new StaticTest(); //2 System.out.println(" 2 "); StaticTest st2 = new StaticTest(); //3 } } What will be the output? Select 1 correct option. a In static, 1, In non - static, 2, In non - static : in that order. b Compilation error. c 1, In static, In non - static, 2, In non - static : in that order. d In static, 1, In non - static, 2, In non - static : in unknown order. e None of the above. Ans: a
  • 8. Question 7 What will happen when you compile and run the following program using the command line: java TestClass 1 2 public class TestClass { public static void main(String[] args) { int i = Integer.parseInt(args[1]); System.out.println(args[i]); } } Select 1 correct option. a It'll print 1 b It'll print 2 c It'll print some junk value. d It'll throw ArrayIndexOutOfBoundsException e It'll throw NumberFormatException Ans: d
  • 9. Question 8 Which of the following are valid at line 1? public class X { line 1: //put statement here. } Select 2 correct options a String s; b String s = 'asdf'; c String s = 'a'; d String s = this.toString(); e String s = asdf; Ans: a&d
  • 10. Question 9 A method is .. Select 1 correct option. a an implementation of an abstraction. b an attribute defining the property of a particular abstraction. c a category of objects. d an operation defining the behavior for a particular abstraction. e a blueprint for making operations. Ans: d
  • 11. Question 10 An instance member ... Select 2 correct options a can be a variable, constant or a method. b is a variable or a constant. c Belongs to the class. d Belongs to an instance of the class. e is same as a local variable. Ans: a&d
  • 12. Question 11 Given the following class, which of these given blocks can be inserted at line 1 without errors? public class InitClass { private static int loop = 15 ; static final int INTERVAL = 10 ; boolean flag ; //line 1 } Select 4 correct options a static {System.out.println("Static"); } b static { loop = 1; } c static { loop += INTERVAL; } d static { INTERVAL = 10; } e { flag = true; loop = 0; } Ans: a,b,c,e
  • 13. Question 12 Which of the following are correct ways to initialize the static variables MAX and CLASS_GUID ? class Widget { static int MAX; //1 static final String CLASS_GUID; // 2 Widget() { //3 } Widget(int k) { //4 } } Select 2 correct options a Modify lines //1 and //2 as : static int MAX = 111; static final String CLASS_GUID = "XYZ123"; b Add the following line just after //2 : static { MAX = 111; CLASS_GUID = "XYZ123"; } c Add the following line just before //1 : { MAX = 111; CLASS_GUID = "XYZ123"; } d Add the following line at //3 as well as //4 : MAX = 111; CLASS_GUID = "XYZ123"; e Only option 3 is valid. Ans: a,b
  • 14. Question 13 What will be the result of attempting to compile and run the following class? public class TestClass { public static void main(String args[ ] ) { int i = 1; int[] iArr = {1}; incr(i) ; incr(iArr) ; System.out.println( "i = " + i + " iArr[0] = " + iArr [ 0 ] ) ; } public static void incr(int n ) { n++ ; } public static void incr(int[ ] n ) { n [ 0 ]++ ; } } Select 1 correct option. a The code will print i = 1 iArr[0] = 1; b The code will print i = 1 iArr[0] = 2; c The code will print i = 2 iArr[0] = 1; d The code will print i = 2 iArr[0] = 2; e The code will not compile. Ans: b
  • 15. Question 14 Consider the following code snippet ... boolean[] b1 = new boolean[2]; boolean[] b2 = {true , false}; System.out.println( "" + (b1[0] == b2[0]) + ", "+ (b1[1] == b2[1]) ); What will it print ? Select 1 correct option. a It will not compile. b It will throw ArrayIndexOutOfBoundsError at Runtime. c It will print false, true. d It will print true, false. e It will print false, false. Ans: c
  • 16. Question 15 What will the following program print? public class TestClass { static String str; public static void main(String[] args) { System.out.println(str); } } Select 1 correct option. a It will not compile. b It will compile but throw an exception at runtime. c It will print 'null' d It will print nothing. e None of the above. Ans: c
  • 17. Question 16 public class TestClass { public static void main(String[] args) { String tom = args[0]; String dick = args[1]; String harry = args[2]; } } What will the value of 'harry' if the program is run from the command line: java TestClass 111 222 333 Select 1 correct option. a 111 b 222 c 333 d It will throw an ArrayIndexOutOfBoundsException e None of the above. Ans: c
  • 18. Question 17 Which of these are keywords in Java? Select 3 correct options a default b NULL c String d throws e long Ans: a,d,e
  • 19. Question 18 Which of the following are valid identifiers? Select 2 correct options a class b $value$ c angstrom d 2much e zer@ Ans: b,c
  • 20. Question 19 public class TestClass { public static void main(String[] args) { String str = "111"; boolean[] bA = new boolean[1]; if( bA[0] ) str = "222"; System.out.println(str); } } What will the above program print? Select 1 correct option. a 111 b 222 c It will not compile as bA[0] is uninitialized. d It will throw an exception at runtime. e None of the above. Ans: a
  • 21. Question 20 What will be the output of the following lines ? System.out.println("" +5 + 6); //1 System.out.println(5 + "" +6); // 2 System.out.println(5 + 6 +""); // 3 System.out.println(5 + 6); // 4 Select 1 correct option. a 56, 56, 11, 11 b 11, 56, 11, 11 c 56, 56, 56, 11 d 56, 56, 56, 56 e 56, 56, 11, 56 Ans: a
  • 22. Question 21 Which of the following is not a primitive data value in Java? Select 2 correct options a "x" b 'x' c 10.2F d Object e false Ans: a,d
  • 23. Question 22 What does the zeroth element of the string array passed to the standard main method contain? Select 1 correct option. a The name of the class. b The string "java". c The number of arguments. d The first argument of the argument list, if present. e None of the above. Ans: d
  • 24. Question 23 What will the following program print? public class TestClass { static boolean b; static int[] ia = new int[1]; static char ch; static boolean[] ba = new boolean[1]; public static void main(String args[]) throws Exception { boolean x = false; if( b ) { x = ( ch == ia[ch]); } else x = ( ba[ch] = b ); System.out.println(x+" "+ba[ch]); } } Select 1 correct option. a true true b true false c false true d false false e It'll not compile. Ans: d
  • 25. Question 24 What will be the result of attempting to compile and run the following code? public class InitClass { public static void main(String args[ ] ) { InitClass obj = new InitClass(5); } int m; static int i1 = 5; static int i2 ; int j = 100; int x; public InitClass(int m) { System.out.println(i1 + " " + i2 + " " + x + " " + j + " " + m); } { j = 30; i2 = 40; } // Instance Initializer static { i1++; } // Static Initializer } Select 1 correct option. a The code will fail to compile, since the instance initializer tries to assign a value to a static member. b The code will fail to compile, since the member variable x will be uninitialized when it is used. c The code will compile without error and will print 6, 40, 0, 30, 5 when run. d The code will compile without error and will print 5, 0, 0, 100, 5 when run. e The code will compile without error and will print 5, 40, 0, 30, 0 when run. Ans: c
  • 26. Question 25 Which code fragments will print the last argument given on the command line to the standard output, and exit without any output and exceptions if no arguments are given? 1. public static void main(String args[ ]) { if (args.length != 0) System.out.println(args[args.length-1]); } 2. public static void main(String args[ ]) { try { System.out.println(args[args.length-1]); } catch (ArrayIndexOutOfBoundsException e) { } } 3. public static void main(String args[ ]) { int i = args.length; if (i != 0) System.out.println(args[i-1]); } 4. public static void main(String args[ ]) { int i = args.length-1; if (i > 0) System.out.println(args[i]); } 5. public static void main(String args[ ]) { try { System.out.println(args[args.length-1]); } catch (NullPointerException e) {} } Select 3 correct options a Code No. 1 b Code No. 2 c Code No. 3 d Code No. 4 e Code No. 5 Ans: a,b,c
  • 27. Question 26 Consider the following class: public class ArgsPrinter { public static void main(String args) { for(int i=0; i<3; i++) { System.out.println(args); } } } What will be printed when the above class is run using the following command line: java ArgsPrinter 1 2 3 4 Select 1 correct option. a123 b ArgsPrinter 1 2 c java ArgsPrinter 1 2 d111 e None of these. Ans: e
  • 28. Question 27 Consider the following class definition: public class TestClass { public static void main(){ new TestClass().sayHello(); } //1 public static void sayHello(){ System.out.println("Static Hello World"); } //2 public void sayHello() { System.out.println("Hello World "); } //3 } What will be the result of compiling and running the class? Select 1 correct option. a It will print 'Hello World'. b It will print 'Static Hello World'. c Compilation error at line 2. d Compilation error at line 3. e Runtime Error. Ans: b
  • 29. Question 28 What will the following program print? public class TestClass { static int someInt = 10; public static void changeIt(int a) { a = 20; } public static void main(String[] args) { changeIt(someInt); System.out.println(someInt); } } Select 1 correct option. a 10 b 20 c It will not compile. d It will throw an exception at runtime. e None of the above. Ans: a
  • 30. Question 29 What is the numerical range of short data type? Select 1 correct option. a It depends on the platform the JVM is running. b 0 to 65535 c -32768 to 32767 d 0 to 32767 e -16384 to 16383 Ans: c