SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
1
JAVA TEST
Time allowed: 30 minutes
NAME:
EMAIL:
DATE:
2
Question# 1
Which of the following are keywords or reserved words in Java?
A. if B. then
C. goto D. while
E. case
Question# 2
A byte can be of what size
A. -128 to 127
B. (-2 power 8)-1 to 2 power 8
C. -255 to 256
D. depends on the particular implementation of the Java Virtual machine
Question# 3
What will happen if you try to compile and run the following code?
public class Q {
public static void main(String argv[]){
int anar[]=new int[]{1, 2, 3};
System.out.println(anar[1]);
}
}
A. 1 B. Error anar is referenced before it is initialized
C. 2 D. Error: size of array must be defined
Question# 4
Given the following declarations
String s1=new String("Hello");
String s2=new String("there");
String s3=new String();
Which of the following are legal operations?
A. s3=s1 + s2; B. s3=s1 - s2;
C. s3=s1 & s2; D. s3=s1 && s2
3
Question# 5
What will happen when you compile and run the following code?
public class MyClass{
static int i;
public static void main(String argv[]){
System.out.println(i);
}
}
A. Error Variable i may not have been initialized
B. null
C. 1
D. 0
Question# 6
Which of the following statements are true?
A. Methods cannot be overriden to be more private
B. Static methods cannot be overloaded
C. Private methods cannot be overloaded
D. An overloaded method cannot throw exceptions not checked in the base class
Question# 7
What will be the result of attempting to compile and run the following code?
abstract class MineBase {
abstract void amethod();
static int i;
}
public class Mine extends MineBase {
public static void main(String argv[]){
int[] ar=new int[5];
for(i=0;i < ar.length;i++)
}
}
A. a sequence of 5 0's will be printed
B. Error: ar is used before it is initialized
C. Error Mine must be declared abstract
D. IndexOutOfBoundes Error
4
Question# 8
What will be output if you try to compile and run the following code, but there is no file called Hello.txt in the current
directory?
import java.io.*;
public class Mine {
public static void main(String argv[]){
Mine m=new Mine();
System.out.println(m.amethod());
}
public int amethod() {
try {
FileInputStream dis=new FileInputStream("Hello.txt");
}catch (FileNotFoundException fne) {
System.out.println("No such file found");
return -1;
}catch(IOException ioe) {
} finally{
System.out.println("Doing finally");
}
return 0;
}
}
A. No such file found
B. No such file found, -1
C. No such file found, Doing finally, -1
D. 0
Question# 9
Which of the following statements are true?
A. System.out.println(-1>>>2); will output a result larger than 10
B. System.out.println(-1>>>2); will output a positive number
C. System.out.println(2>>1); will output the number 1
D. System.out.println(1<<<2); will output the number 4
5
Question# 10
What will be displayed when you attempt to compile and run the following code
//Code start
import java.awt.*;
public class Butt extends Frame{
public static void main(String argv[]){
Butt MyBut=new Butt();
}
Butt(){
Button HelloBut=new Button("Hello");
Button ByeBut=new Button("Bye");
add(HelloBut);
add(ByeBut);
setSize(300,300);
setVisible(true);
}
}
//Code end
A. Two buttons side by side occupying all of the frame, Hello on the left and Bye on the right
B. One button occupying the entire frame saying Hello
C. One button occupying the entire frame saying Bye
D. Two buttons at the top of the frame one saying Hello the other saying Bye
Question# 12 - 11
If g is a graphics instance what will the following code draw on the screen?
g.fillArc(45,90,50,50,90,180);
A. An arc bounded by a box of height 45, width 90 with a centre point of 50, 50, starting at an angle of 90 degrees
traversing through 180 degrees counter clockwise.
B. An arc bounded by a box of height 50, width 50, with a centre point of 45, 90, starting at an angle of 90 degrees
traversing through 180 degrees clockwise.
C. An arc bounded by a box of height 50, width 50 with a top left at coordinates of 45, 90, starting at 90 degrees and
traversing through 180 degrees counter clockwise.
D. An arc starting at 45 degrees, traversing through 90 degrees clockwise bounded by a box of height 50, width 50
with a centre point of 90, 180.
6
Question# 11 - 12
If you wanted to find out where the position of the letter v (ie return 2) in the string s containing "Java", which of the
following could you use?
A. mid(2,s); B. charAt(2);
C. s.indexOf('v'); D. indexOf(s,'v');
Question# 13
What code placed after the comment //For loop would populate the elements of the array ia[] with values of the variable i.?
public class Lin{
public static void main(String argv[]){
Lin l = new Lin();
l.amethod();
}
public void amethod(){
int ia[] = new int[4];
//Start For loop
{
ia[i]=i;
System.out.println(ia[i]);
}
}
}
A. for(int i=0; i < ia.length() -1; i++)
B. for(int i=0; i < ia.length(); i++)
C. for(int i=1; i < 4; i++)
D. for(int i=0; i< ia.length;i++)
Question# 15 - 14
An Applet has its Layout Manager set to the default of FlowLayout. What code would be correct to change to another
Layout manager?
A. set LayoutManager(new GridLayout());
B. set Layout(new GridLayout(2,2));
C. setGridLayout(2,2);
D. setBorderLayout();
7
Question# 14 - 15
Which of the following will output -4.0
A. System.out.println(Math.floor(-4.7)); B. System.out.println(Math.round(-4.7));
C. System.out.println(Math.ceil(-4.7)); D. System.out.println(Math.min(-4.7));
Question# 16
What will be the result when you attempt to compile and run the following code?
public class Conv{
public static void main(String argv[]){
Conv c=new Conv();
String s=new String("ello");
c.amethod(s);
}
public void amethod(String s){
char c='H';
c+=s;
System.out.println(c);
}
}
A. Compilation and output the string "Hello"
B. Compilation and output the String "ello"
C. Compilation and output the string elloH
D. Compile time error
Question# 23 - 17
What will the following code print out?
public class Oct{
public static void main(String argv[]){
Oct o = new Oct();
o.amethod();
}
public void amethod(){
int oi= 012;
System.out.println(oi);
}
}
A. 12 B. 012
C. 10 D. 10.0
Question# 17 - 18
8
What will be printed out if this code is run with the following command line?
java Myprog good morning
public class Myprog{
public static void main(String argv[]){
System.out.println(argv[2])
}
}
A. myprog
B. good
C. morning
D. Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"
Question# 18 - 19
If you create a TextField with a constructor to set it to occupy 5 columns, what difference will it make if you use it with a
proportional font (ie Times Roman) or a fixed pitch typewriter style font (Courier)
A. With a fixed font you will see 5 characters,with a proportional it will depend on the width of the characters
B. With a fixed font you will see 5 characters,with a proportional it will cause the field to expand to fit the text
C. The columns setting does not affect the number of characters displayed
D. Both will show exactly 5 characters
Question# 19 - 20
Given the following code:
import java.awt.*;
public class SetF extends Frame{
public static void main(String argv[]){
SetF s=new SetF();
s.setSize(300,200);
s.setVisible(true);
}
}
How could you set the frame su
A. s.setBackground(Color.pink);
B. s.setColor(PINK);
C. s.Background(pink);
D. s.color=Color.pink
Question# 20 - 21
Given the following code what will be output?
9
public class Pass{
static int j=20;
public static void main(String argv[]){
int i=10;
Pass p = new Pass();
p.amethod(i);
System.out.println(i);
System.out.println(j);
}
public void amethod(int x){
x=x*2;
j=j*2;
}
}
A. Error: amethod parameter does not match variable
B. 20 and 40
C. 10 and 40
D. 10, and 20
Question# 21 - 22
Which of the following can you perform using the File class?
A. Change the current directory
B. Return the name of the parent directory
C. Delete a file
D. Find if a file contains text or binary information
Question# 24 - 23
What is the result of the following operation?
System.out.println(4 | 3);
A. 6 B. 0
C. 1 D. 7
10
Question# 22 - 24
What will be the result when you try to compile and run the following code?
private class Base{
Base(){
int i = 100;
System.out.println(i);
}
}
public class Pri extends Base{
static int i = 200;
public static void main(String argv[]){
Pri p = new Pri();
System.out.println(i);
}
}
A. Error at compile time B. 200
C. 100 followed by 200 D. 100
Question# 25
What will happen when you try compiling and running this code?
public class Ref{
public static void main(String argv[]){
Ref r = new Ref();
r.amethod(r);
}
public void amethod(Ref r){
int i=99;
multi(r);
System.out.println(i);
}
public void mult(Ref r){
r.i = r.i*2;
}
}
A. Error at compile time B. An output of 99
C. An output of 198 D. An error at runtime
Question# 27 - 26
11
Which of the following will compile without error?
A.
import java.awt.*;
package Mypackage;
class Myclass{}
B.
package MyPackage;
import java.awt.*;
class MyClass{}
C.
package MyPackage;
importjava.awt.*;
class MyClass{}
Question# 28 - 27
Which of the following will successfully crate an instance of the Vector class and add an element?
A.
Vector v=new Vector(99);
v[1]=99;
C.
Vector v=new Vector();
v.add(99);
B.
Vector v=new Vetor();
v.addElement(99);
D.
Vector v=new Vector(100);
v.addElement("99");
Question# 29 - 28
What will happen when you compile and run the following code?
public class Scope{
private int i;
public static void main(String argv[])}
Scope s = new Scope();
s.amethod();
}//End of main
public static void amethod(){
System.out.println(i);
}//end of amethod
}//End of class
A. A value of 0 will be printed out
B. Nothing will be printed out
C. A compile time error
D. A compile time error complaining of the csope of the variable i
Question# 26 - 29
What will be the result when you attempt to compile this program?
12
public class Rand{
public static void main(String argv[]){
int iRand;
iRand = Math.random();
System.out.println(iRand);
}
}
A. Compile time error referring to a cast problem
B. A random number between 1 and 10
C. A random number between 0 and 1
D. A compile time error about random being an unrecognised method
Question# 30
What will happen when you attempt to compile and run the following code
class Base{
private void amethod(int iBase){
System.out.println("Base.amethod");
}
}
class Over extends Base{
public static void main(String argv[]){
Over o = new Over();
int iBase=0;
o.amethod(iBase);
}
public void amethod(int iOver){
System.out.println("Over.amethod");
}
}
A. Runtime error complaining that Base.amethod is private
B. Output of "Base.amethod"
C. Output of "Over.amethod"
D. Compile time error complaining that Base.amethod is private
~ The end ~

More Related Content

PDF
Bộ câu hỏi Chủ nghĩa xã hội Khoa học có đáp án.pdf
DOCX
40 cau trac nghiem kinh te chinh tri
PDF
Ôn thi mạng máy tính
DOC
PHÂN TÍCH THIẾT KẾ HỆ THỐNG BÁN HÀNG QUA MẠNG
PPTX
Slide Báo Cáo Đồ Án Tốt Nghiệp CNTT
PDF
Thiết kế mạng lan cho tòa nhà 3 tầng - luận văn, đồ án, đề tài tốt nghiệp (Đặ...
PDF
Processor Organization and Architecture
PPTX
Các mặt cắt siêu âm tim cơ bản
Bộ câu hỏi Chủ nghĩa xã hội Khoa học có đáp án.pdf
40 cau trac nghiem kinh te chinh tri
Ôn thi mạng máy tính
PHÂN TÍCH THIẾT KẾ HỆ THỐNG BÁN HÀNG QUA MẠNG
Slide Báo Cáo Đồ Án Tốt Nghiệp CNTT
Thiết kế mạng lan cho tòa nhà 3 tầng - luận văn, đồ án, đề tài tốt nghiệp (Đặ...
Processor Organization and Architecture
Các mặt cắt siêu âm tim cơ bản

What's hot (20)

PPTX
Ứng dụng NLP vào việc xác định ý muốn người dùng (Intent Detection) và sửa lỗ...
PDF
Bài tập nhập môn lập trình
PPTX
SỰ HẠN CHẾ CỦA IPv4 VÀ SỰ RA ĐỜI CỦA IPV6
PDF
NGHIÊN CỨU PHƯƠNG PHÁP QUAY LUI VÀ ỨNG DỤNG GIẢI BÀI TOÁN SUDOKU
DOC
De thi qlda cntt itc vdc trac nghiem 05-2006
PDF
Bo de toan roi rac (on thi cao hoc khmt)
DOC
Lập trình c++ có lời giải 2
DOCX
tổng hợp bài tập java có đáp án chi tiết
PPT
Giáo trình Phân tích và thiết kế giải thuật - CHAP 5
DOC
Tim hieu thanh ghi in asm
PPT
chuong 3. quan he
DOC
Nghiên cứu chuẩn ISO/IEC 9126 trong đánh giá chất lượng phần mềm
PDF
Phụ thuộc hàm và các dạng chuẩn - dhcntt
DOCX
Giới thiệu về Rational Rose và Các diagram
PDF
Automata slide DHBKHCM [S2NUCE.blogspot.com]
DOCX
Đề thi mẫu trắc nghiệm cấu trúc dữ liệu cà giải thuật
PDF
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
PPT
MATMA - Chuong2
PDF
Về kỹ thuật Attention trong mô hình sequence-to-sequence tại hội nghị ACL 2017
PDF
mạch tổ hợp và mạch trình tự - Điện tử Đo lường
Ứng dụng NLP vào việc xác định ý muốn người dùng (Intent Detection) và sửa lỗ...
Bài tập nhập môn lập trình
SỰ HẠN CHẾ CỦA IPv4 VÀ SỰ RA ĐỜI CỦA IPV6
NGHIÊN CỨU PHƯƠNG PHÁP QUAY LUI VÀ ỨNG DỤNG GIẢI BÀI TOÁN SUDOKU
De thi qlda cntt itc vdc trac nghiem 05-2006
Bo de toan roi rac (on thi cao hoc khmt)
Lập trình c++ có lời giải 2
tổng hợp bài tập java có đáp án chi tiết
Giáo trình Phân tích và thiết kế giải thuật - CHAP 5
Tim hieu thanh ghi in asm
chuong 3. quan he
Nghiên cứu chuẩn ISO/IEC 9126 trong đánh giá chất lượng phần mềm
Phụ thuộc hàm và các dạng chuẩn - dhcntt
Giới thiệu về Rational Rose và Các diagram
Automata slide DHBKHCM [S2NUCE.blogspot.com]
Đề thi mẫu trắc nghiệm cấu trúc dữ liệu cà giải thuật
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
MATMA - Chuong2
Về kỹ thuật Attention trong mô hình sequence-to-sequence tại hội nghị ACL 2017
mạch tổ hợp và mạch trình tự - Điện tử Đo lường
Ad

Similar to FSOFT - Test Java Exam (20)

PDF
1z0 851 exam-java standard edition 6 programmer certified professional
PPTX
UNIT 2 LOOP CONTROL.pptx
PDF
Cbse marking scheme 2006 2011
PDF
Core java
DOC
PPTX
Technical aptitude test 2 CSE
PDF
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
PDF
Fnt software solutions placement paper
DOCX
Java Questions and Answers
ODP
Java Generics
DOCX
Simulado java se 7 programmer
PDF
Scjp6.0
PDF
1z0 804 exam-java se 7 programmer ii
PPTX
Chapter 3 of Java 17 Certification sample questions
PDF
Computer science ms
PDF
MATLAB Questions and Answers.pdf
ODP
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
DOCX
703497334-ICSE-Class-9-Computer-Applications-Sample-Question-Papers.docx
PDF
Redo midterm
1z0 851 exam-java standard edition 6 programmer certified professional
UNIT 2 LOOP CONTROL.pptx
Cbse marking scheme 2006 2011
Core java
Technical aptitude test 2 CSE
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
Fnt software solutions placement paper
Java Questions and Answers
Java Generics
Simulado java se 7 programmer
Scjp6.0
1z0 804 exam-java se 7 programmer ii
Chapter 3 of Java 17 Certification sample questions
Computer science ms
MATLAB Questions and Answers.pdf
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
703497334-ICSE-Class-9-Computer-Applications-Sample-Question-Papers.docx
Redo midterm
Ad

Recently uploaded (20)

PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
System and Network Administraation Chapter 3
PPTX
history of c programming in notes for students .pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Understanding Forklifts - TECH EHS Solution
PDF
AI in Product Development-omnex systems
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Essential Infomation Tech presentation.pptx
PPTX
ai tools demonstartion for schools and inter college
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Transform Your Business with a Software ERP System
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
Softaken Excel to vCard Converter Software.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
How to Choose the Right IT Partner for Your Business in Malaysia
Navsoft: AI-Powered Business Solutions & Custom Software Development
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
System and Network Administraation Chapter 3
history of c programming in notes for students .pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Understanding Forklifts - TECH EHS Solution
AI in Product Development-omnex systems
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Migrate SBCGlobal Email to Yahoo Easily
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Design an Analysis of Algorithms II-SECS-1021-03
Essential Infomation Tech presentation.pptx
ai tools demonstartion for schools and inter college
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Transform Your Business with a Software ERP System
wealthsignaloriginal-com-DS-text-... (1).pdf

FSOFT - Test Java Exam

  • 1. 1 JAVA TEST Time allowed: 30 minutes NAME: EMAIL: DATE:
  • 2. 2 Question# 1 Which of the following are keywords or reserved words in Java? A. if B. then C. goto D. while E. case Question# 2 A byte can be of what size A. -128 to 127 B. (-2 power 8)-1 to 2 power 8 C. -255 to 256 D. depends on the particular implementation of the Java Virtual machine Question# 3 What will happen if you try to compile and run the following code? public class Q { public static void main(String argv[]){ int anar[]=new int[]{1, 2, 3}; System.out.println(anar[1]); } } A. 1 B. Error anar is referenced before it is initialized C. 2 D. Error: size of array must be defined Question# 4 Given the following declarations String s1=new String("Hello"); String s2=new String("there"); String s3=new String(); Which of the following are legal operations? A. s3=s1 + s2; B. s3=s1 - s2; C. s3=s1 & s2; D. s3=s1 && s2
  • 3. 3 Question# 5 What will happen when you compile and run the following code? public class MyClass{ static int i; public static void main(String argv[]){ System.out.println(i); } } A. Error Variable i may not have been initialized B. null C. 1 D. 0 Question# 6 Which of the following statements are true? A. Methods cannot be overriden to be more private B. Static methods cannot be overloaded C. Private methods cannot be overloaded D. An overloaded method cannot throw exceptions not checked in the base class Question# 7 What will be the result of attempting to compile and run the following code? abstract class MineBase { abstract void amethod(); static int i; } public class Mine extends MineBase { public static void main(String argv[]){ int[] ar=new int[5]; for(i=0;i < ar.length;i++) } } A. a sequence of 5 0's will be printed B. Error: ar is used before it is initialized C. Error Mine must be declared abstract D. IndexOutOfBoundes Error
  • 4. 4 Question# 8 What will be output if you try to compile and run the following code, but there is no file called Hello.txt in the current directory? import java.io.*; public class Mine { public static void main(String argv[]){ Mine m=new Mine(); System.out.println(m.amethod()); } public int amethod() { try { FileInputStream dis=new FileInputStream("Hello.txt"); }catch (FileNotFoundException fne) { System.out.println("No such file found"); return -1; }catch(IOException ioe) { } finally{ System.out.println("Doing finally"); } return 0; } } A. No such file found B. No such file found, -1 C. No such file found, Doing finally, -1 D. 0 Question# 9 Which of the following statements are true? A. System.out.println(-1>>>2); will output a result larger than 10 B. System.out.println(-1>>>2); will output a positive number C. System.out.println(2>>1); will output the number 1 D. System.out.println(1<<<2); will output the number 4
  • 5. 5 Question# 10 What will be displayed when you attempt to compile and run the following code //Code start import java.awt.*; public class Butt extends Frame{ public static void main(String argv[]){ Butt MyBut=new Butt(); } Butt(){ Button HelloBut=new Button("Hello"); Button ByeBut=new Button("Bye"); add(HelloBut); add(ByeBut); setSize(300,300); setVisible(true); } } //Code end A. Two buttons side by side occupying all of the frame, Hello on the left and Bye on the right B. One button occupying the entire frame saying Hello C. One button occupying the entire frame saying Bye D. Two buttons at the top of the frame one saying Hello the other saying Bye Question# 12 - 11 If g is a graphics instance what will the following code draw on the screen? g.fillArc(45,90,50,50,90,180); A. An arc bounded by a box of height 45, width 90 with a centre point of 50, 50, starting at an angle of 90 degrees traversing through 180 degrees counter clockwise. B. An arc bounded by a box of height 50, width 50, with a centre point of 45, 90, starting at an angle of 90 degrees traversing through 180 degrees clockwise. C. An arc bounded by a box of height 50, width 50 with a top left at coordinates of 45, 90, starting at 90 degrees and traversing through 180 degrees counter clockwise. D. An arc starting at 45 degrees, traversing through 90 degrees clockwise bounded by a box of height 50, width 50 with a centre point of 90, 180.
  • 6. 6 Question# 11 - 12 If you wanted to find out where the position of the letter v (ie return 2) in the string s containing "Java", which of the following could you use? A. mid(2,s); B. charAt(2); C. s.indexOf('v'); D. indexOf(s,'v'); Question# 13 What code placed after the comment //For loop would populate the elements of the array ia[] with values of the variable i.? public class Lin{ public static void main(String argv[]){ Lin l = new Lin(); l.amethod(); } public void amethod(){ int ia[] = new int[4]; //Start For loop { ia[i]=i; System.out.println(ia[i]); } } } A. for(int i=0; i < ia.length() -1; i++) B. for(int i=0; i < ia.length(); i++) C. for(int i=1; i < 4; i++) D. for(int i=0; i< ia.length;i++) Question# 15 - 14 An Applet has its Layout Manager set to the default of FlowLayout. What code would be correct to change to another Layout manager? A. set LayoutManager(new GridLayout()); B. set Layout(new GridLayout(2,2)); C. setGridLayout(2,2); D. setBorderLayout();
  • 7. 7 Question# 14 - 15 Which of the following will output -4.0 A. System.out.println(Math.floor(-4.7)); B. System.out.println(Math.round(-4.7)); C. System.out.println(Math.ceil(-4.7)); D. System.out.println(Math.min(-4.7)); Question# 16 What will be the result when you attempt to compile and run the following code? public class Conv{ public static void main(String argv[]){ Conv c=new Conv(); String s=new String("ello"); c.amethod(s); } public void amethod(String s){ char c='H'; c+=s; System.out.println(c); } } A. Compilation and output the string "Hello" B. Compilation and output the String "ello" C. Compilation and output the string elloH D. Compile time error Question# 23 - 17 What will the following code print out? public class Oct{ public static void main(String argv[]){ Oct o = new Oct(); o.amethod(); } public void amethod(){ int oi= 012; System.out.println(oi); } } A. 12 B. 012 C. 10 D. 10.0 Question# 17 - 18
  • 8. 8 What will be printed out if this code is run with the following command line? java Myprog good morning public class Myprog{ public static void main(String argv[]){ System.out.println(argv[2]) } } A. myprog B. good C. morning D. Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2" Question# 18 - 19 If you create a TextField with a constructor to set it to occupy 5 columns, what difference will it make if you use it with a proportional font (ie Times Roman) or a fixed pitch typewriter style font (Courier) A. With a fixed font you will see 5 characters,with a proportional it will depend on the width of the characters B. With a fixed font you will see 5 characters,with a proportional it will cause the field to expand to fit the text C. The columns setting does not affect the number of characters displayed D. Both will show exactly 5 characters Question# 19 - 20 Given the following code: import java.awt.*; public class SetF extends Frame{ public static void main(String argv[]){ SetF s=new SetF(); s.setSize(300,200); s.setVisible(true); } } How could you set the frame su A. s.setBackground(Color.pink); B. s.setColor(PINK); C. s.Background(pink); D. s.color=Color.pink Question# 20 - 21 Given the following code what will be output?
  • 9. 9 public class Pass{ static int j=20; public static void main(String argv[]){ int i=10; Pass p = new Pass(); p.amethod(i); System.out.println(i); System.out.println(j); } public void amethod(int x){ x=x*2; j=j*2; } } A. Error: amethod parameter does not match variable B. 20 and 40 C. 10 and 40 D. 10, and 20 Question# 21 - 22 Which of the following can you perform using the File class? A. Change the current directory B. Return the name of the parent directory C. Delete a file D. Find if a file contains text or binary information Question# 24 - 23 What is the result of the following operation? System.out.println(4 | 3); A. 6 B. 0 C. 1 D. 7
  • 10. 10 Question# 22 - 24 What will be the result when you try to compile and run the following code? private class Base{ Base(){ int i = 100; System.out.println(i); } } public class Pri extends Base{ static int i = 200; public static void main(String argv[]){ Pri p = new Pri(); System.out.println(i); } } A. Error at compile time B. 200 C. 100 followed by 200 D. 100 Question# 25 What will happen when you try compiling and running this code? public class Ref{ public static void main(String argv[]){ Ref r = new Ref(); r.amethod(r); } public void amethod(Ref r){ int i=99; multi(r); System.out.println(i); } public void mult(Ref r){ r.i = r.i*2; } } A. Error at compile time B. An output of 99 C. An output of 198 D. An error at runtime Question# 27 - 26
  • 11. 11 Which of the following will compile without error? A. import java.awt.*; package Mypackage; class Myclass{} B. package MyPackage; import java.awt.*; class MyClass{} C. package MyPackage; importjava.awt.*; class MyClass{} Question# 28 - 27 Which of the following will successfully crate an instance of the Vector class and add an element? A. Vector v=new Vector(99); v[1]=99; C. Vector v=new Vector(); v.add(99); B. Vector v=new Vetor(); v.addElement(99); D. Vector v=new Vector(100); v.addElement("99"); Question# 29 - 28 What will happen when you compile and run the following code? public class Scope{ private int i; public static void main(String argv[])} Scope s = new Scope(); s.amethod(); }//End of main public static void amethod(){ System.out.println(i); }//end of amethod }//End of class A. A value of 0 will be printed out B. Nothing will be printed out C. A compile time error D. A compile time error complaining of the csope of the variable i Question# 26 - 29 What will be the result when you attempt to compile this program?
  • 12. 12 public class Rand{ public static void main(String argv[]){ int iRand; iRand = Math.random(); System.out.println(iRand); } } A. Compile time error referring to a cast problem B. A random number between 1 and 10 C. A random number between 0 and 1 D. A compile time error about random being an unrecognised method Question# 30 What will happen when you attempt to compile and run the following code class Base{ private void amethod(int iBase){ System.out.println("Base.amethod"); } } class Over extends Base{ public static void main(String argv[]){ Over o = new Over(); int iBase=0; o.amethod(iBase); } public void amethod(int iOver){ System.out.println("Over.amethod"); } } A. Runtime error complaining that Base.amethod is private B. Output of "Base.amethod" C. Output of "Over.amethod" D. Compile time error complaining that Base.amethod is private ~ The end ~