SlideShare a Scribd company logo
OCJP
www.javaexpert.co.in
Q. class Foo {
static void alpha() { /*code here */ }
void beta() { /*code here */ }
}
A. Foo.beta() is a valid invocation of beta().
B. Foo.alpha() is a valid invocation of alpha().
C. Method beta() can directly call method alpha().
D. Method alpha() can directly call method beta().
OCJP
www.javaexpert.co.in
Q. public class demo {
static public void main(String [] yahoo) {
for(int x = 1; x < yahoo.length; x++) {
System.out.print(yahoo[x] + " "); }
}
and the command line invocation:
java demo a b c
Output is : -
A. b c
B. a b c
C. Compilation fails.
D. An exception is thrown at runtime.
OCJP
www.javaexpert.co.in
Q. public class Yippee {
public static void main(String [] args) {
for(int x = 1; x < args.length; x++) {
System.out.print(args[x] + " "); }}}
From command line
java Yippee
java Yippee 1 2 3 4
A. No output 1 2 3 4
B. No output 2 3 4
C. An exception is thrown at runtime. 2 3 4
D. An exception is thrown at runtime. 1 2 3 4
OCJP
www.javaexpert.co.in
Q. package utils;
public class Repetition {
public static String twice(String s) { return s + s; } }
and given another class Demo:// insert code here
public class Demo {
public static void main(String[] args) {
System.out.println(twice("pizza"));}}
Which code should be inserted at line 1 of Demo.java to compile and run Demo to print
"pizzapizza"?
A. import utils.*;
B. static import utils.*;
C. import utils.Repetition.*;
D. static import utils.Repetition.*;
E. import utils.Repetition.twice();
F. import static utils.Repetition.twice;
G. static import utils.Repetition.twice;
OCJP
www.javaexpert.co.in
Q. A JavaBeans component has the following field:
private boolean enabled;
Which two pairs of method declarations follow the JavaBeans standard for
accessing this field? (select any two).
A. public void setEnabled( boolean enabled )
public boolean getEnabled()
B. public void setEnabled( boolean enabled )
public void isEnabled()
C. public void setEnabled( boolean enabled )
public boolean isEnabled()
D. public boolean setEnabled( boolean enabled )
public boolean getEnabled()
OCJP
www.javaexpert.co.in
Q. package util;
public class BitUtils {
public static void process(byte[]) { /* more code here */ }}
package app;
public class SomeApp {
public static void main(String[] args) {
byte[] bytes = new byte[256]; // insert code here}}
What is required at line 5 in class SomeApp to use the process method of BitUtils?
A. process(bytes);
B. BitUtils.process(bytes);
C. util.BitUtils.process(bytes);
D. SomeApp cannot use methods in BitUtils.
E. import util.BitUtils.*; process(bytes);
OCJP
www.javaexpert.co.in
Q. enum Example { ONE, TWO, THREE }
Which statement is true?
A. The expressions (ONE == ONE) and ONE.equals(ONE) are both guaranteed
to be true.
B. The expression (ONE < TWO) is guaranteed to be true and
ONE.compareTo(TWO) is guaranteed to be less than one.
C. The Example values cannot be used in a raw java.util.HashMap; instead, the
programmer must use a java.util.EnumMap.
D. The Example values can be used in a java.util.SortedSet, but the set will NOT
be sorted because enumerated types do NOT implement java.lang.Comparable.
OCJP
www.javaexpert.co.in
Q. public abstract class Shape {
private int x;
private int y;
public abstract void draw();
public void setAnchor(int x, int y) {
this.x = x; this.y = y;}}
Which two classes use the Shape class correctly?
A. public class Circle implements Shape { private int radius; }
B. public abstract class Circle extends Shape { private int radius; }
C. public class Circle extends Shape { private int radius; public void draw(); }
D. public class Circle extends Shape { private int radius; public void draw() {/* code here */}
E. public abstract class Circle implements Shape { private int radius; public void draw() { /* code
here */ }
OCJP
www.javaexpert.co.in
Q. class Nav{
public enum Direction { NORTH, SOUTH, EAST, WEST } }
public class Sprite{ // insert code here }
Which code, inserted at line 14, allows the Sprite class to compile?
A. Direction d = NORTH;
B. Nav.Direction d = NORTH;
C. Direction d = Direction.NORTH;
D. Nav.Direction d = Nav.Direction.NORTH;
OCJP
www.javaexpert.co.in
Q. int [] x = {1, 2, 3, 4, 5}; //Line 1
int y[] = x; // Line 2
System.out.println(y[2]); // Line 3
Which statement is true? // Line 4
A. Line 3 will print the value 2.
B. Line 3 will print the value 3.
C. Compilation will fail because of an error in line 1.
D. Compilation will fail because of an error in line 2.
OCJP
www.javaexpert.co.in

More Related Content

PDF
Orthogonal Functional Architecture
PPTX
SoCal Code Camp 2015: An introduction to Java 8
PDF
Introduction to programming with ZIO functional effects
PDF
Java practical(baca sem v)
DOC
Final JAVA Practical of BCA SEM-5.
PDF
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
PPTX
Java Programs
Orthogonal Functional Architecture
SoCal Code Camp 2015: An introduction to Java 8
Introduction to programming with ZIO functional effects
Java practical(baca sem v)
Final JAVA Practical of BCA SEM-5.
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
Java Programs

What's hot (18)

PDF
Functional Programming 101 with Scala and ZIO @FunctionalWorld
PDF
Java Simple Programs
PPT
C# Variables and Operators
PDF
Fnt software solutions placement paper
PPTX
Interface
PDF
All Aboard The Scala-to-PureScript Express!
PDF
&Y tgs P kii for
PDF
PDF
Improving Android Performance at Droidcon UK 2014
PDF
One Monad to Rule Them All
PPTX
Operators
DOCX
Multiple choice questions for Java io,files and inheritance
PPTX
Java simple programs
PDF
Scalaz 8 vs Akka Actors
PDF
MTL Versus Free
PDF
The Design of the Scalaz 8 Effect System
PDF
Juan josefumeroarray14
Functional Programming 101 with Scala and ZIO @FunctionalWorld
Java Simple Programs
C# Variables and Operators
Fnt software solutions placement paper
Interface
All Aboard The Scala-to-PureScript Express!
&Y tgs P kii for
Improving Android Performance at Droidcon UK 2014
One Monad to Rule Them All
Operators
Multiple choice questions for Java io,files and inheritance
Java simple programs
Scalaz 8 vs Akka Actors
MTL Versus Free
The Design of the Scalaz 8 Effect System
Juan josefumeroarray14
Ad

Viewers also liked (9)

PDF
LiveAdmins and Gitex 2016
PPTX
Canada Employment and Labour market for November 2016 - Analysis and Commentary
DOCX
PLANIFICADOR DE PROYECTOS
PPTX
Carpeta digital bertona arenas
PPTX
PPTX
Google maps (equipo) (1)
PPT
Social marketing
PDF
Газета "Наш край", №12, 2-15 декабря, - русский
PPT
Características basicas del voleibol
LiveAdmins and Gitex 2016
Canada Employment and Labour market for November 2016 - Analysis and Commentary
PLANIFICADOR DE PROYECTOS
Carpeta digital bertona arenas
Google maps (equipo) (1)
Social marketing
Газета "Наш край", №12, 2-15 декабря, - русский
Características basicas del voleibol
Ad

Similar to Language fundamentals ocjp (20)

DOCX
Comp 328 final guide
TXT
CORE JAVA
PDF
1z0 851 exam-java standard edition 6 programmer certified professional
PPT
Java language fundamentals
PDF
Java MCQ Important Questions and Answers
DOCX
Simulado java se 7 programmer
DOCX
FSOFT - Test Java Exam
DOC
202: When the user clicks a JCheckBox, a(n) occurs.
DOC
22: The logical relationship between radio buttons is maintained by objects o...
DOC
17: provides the basic attributes and behaviors of a window—a title bar at th...
DOC
7: Assume the following class declaration.
DOC
3: A(n) ________ enables a program to read data from the user.
DOC
10: In the Java graphics system, coordinate units are measured in ________.
DOC
19: When the user presses Enter in a JTextField, the GUI component generates ...
DOC
18: Which of the following does not generate an event?
DOC
12: When an object is concatenated with a String
DOC
21: Which method determines if a JRadioButton is selected?
DOC
5: Every Java application is required to have
DOC
15: Which method call converts the value in variable stringVariable to an int...
DOC
8: Which statement below could be used to randomly select a state from an arr...
Comp 328 final guide
CORE JAVA
1z0 851 exam-java standard edition 6 programmer certified professional
Java language fundamentals
Java MCQ Important Questions and Answers
Simulado java se 7 programmer
FSOFT - Test Java Exam
202: When the user clicks a JCheckBox, a(n) occurs.
22: The logical relationship between radio buttons is maintained by objects o...
17: provides the basic attributes and behaviors of a window—a title bar at th...
7: Assume the following class declaration.
3: A(n) ________ enables a program to read data from the user.
10: In the Java graphics system, coordinate units are measured in ________.
19: When the user presses Enter in a JTextField, the GUI component generates ...
18: Which of the following does not generate an event?
12: When an object is concatenated with a String
21: Which method determines if a JRadioButton is selected?
5: Every Java application is required to have
15: Which method call converts the value in variable stringVariable to an int...
8: Which statement below could be used to randomly select a state from an arr...

Recently uploaded (20)

PDF
Basic Mud Logging Guide for educational purpose
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Insiders guide to clinical Medicine.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Institutional Correction lecture only . . .
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Cell Structure & Organelles in detailed.
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Basic Mud Logging Guide for educational purpose
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Supply Chain Operations Speaking Notes -ICLT Program
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Insiders guide to clinical Medicine.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Microbial disease of the cardiovascular and lymphatic systems
Institutional Correction lecture only . . .
Abdominal Access Techniques with Prof. Dr. R K Mishra
Anesthesia in Laparoscopic Surgery in India
Cell Structure & Organelles in detailed.
01-Introduction-to-Information-Management.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
TR - Agricultural Crops Production NC III.pdf
Computing-Curriculum for Schools in Ghana
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx

Language fundamentals ocjp

  • 1. OCJP www.javaexpert.co.in Q. class Foo { static void alpha() { /*code here */ } void beta() { /*code here */ } } A. Foo.beta() is a valid invocation of beta(). B. Foo.alpha() is a valid invocation of alpha(). C. Method beta() can directly call method alpha(). D. Method alpha() can directly call method beta().
  • 2. OCJP www.javaexpert.co.in Q. public class demo { static public void main(String [] yahoo) { for(int x = 1; x < yahoo.length; x++) { System.out.print(yahoo[x] + " "); } } and the command line invocation: java demo a b c Output is : - A. b c B. a b c C. Compilation fails. D. An exception is thrown at runtime.
  • 3. OCJP www.javaexpert.co.in Q. public class Yippee { public static void main(String [] args) { for(int x = 1; x < args.length; x++) { System.out.print(args[x] + " "); }}} From command line java Yippee java Yippee 1 2 3 4 A. No output 1 2 3 4 B. No output 2 3 4 C. An exception is thrown at runtime. 2 3 4 D. An exception is thrown at runtime. 1 2 3 4
  • 4. OCJP www.javaexpert.co.in Q. package utils; public class Repetition { public static String twice(String s) { return s + s; } } and given another class Demo:// insert code here public class Demo { public static void main(String[] args) { System.out.println(twice("pizza"));}} Which code should be inserted at line 1 of Demo.java to compile and run Demo to print "pizzapizza"? A. import utils.*; B. static import utils.*; C. import utils.Repetition.*; D. static import utils.Repetition.*; E. import utils.Repetition.twice(); F. import static utils.Repetition.twice; G. static import utils.Repetition.twice;
  • 5. OCJP www.javaexpert.co.in Q. A JavaBeans component has the following field: private boolean enabled; Which two pairs of method declarations follow the JavaBeans standard for accessing this field? (select any two). A. public void setEnabled( boolean enabled ) public boolean getEnabled() B. public void setEnabled( boolean enabled ) public void isEnabled() C. public void setEnabled( boolean enabled ) public boolean isEnabled() D. public boolean setEnabled( boolean enabled ) public boolean getEnabled()
  • 6. OCJP www.javaexpert.co.in Q. package util; public class BitUtils { public static void process(byte[]) { /* more code here */ }} package app; public class SomeApp { public static void main(String[] args) { byte[] bytes = new byte[256]; // insert code here}} What is required at line 5 in class SomeApp to use the process method of BitUtils? A. process(bytes); B. BitUtils.process(bytes); C. util.BitUtils.process(bytes); D. SomeApp cannot use methods in BitUtils. E. import util.BitUtils.*; process(bytes);
  • 7. OCJP www.javaexpert.co.in Q. enum Example { ONE, TWO, THREE } Which statement is true? A. The expressions (ONE == ONE) and ONE.equals(ONE) are both guaranteed to be true. B. The expression (ONE < TWO) is guaranteed to be true and ONE.compareTo(TWO) is guaranteed to be less than one. C. The Example values cannot be used in a raw java.util.HashMap; instead, the programmer must use a java.util.EnumMap. D. The Example values can be used in a java.util.SortedSet, but the set will NOT be sorted because enumerated types do NOT implement java.lang.Comparable.
  • 8. OCJP www.javaexpert.co.in Q. public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y;}} Which two classes use the Shape class correctly? A. public class Circle implements Shape { private int radius; } B. public abstract class Circle extends Shape { private int radius; } C. public class Circle extends Shape { private int radius; public void draw(); } D. public class Circle extends Shape { private int radius; public void draw() {/* code here */} E. public abstract class Circle implements Shape { private int radius; public void draw() { /* code here */ }
  • 9. OCJP www.javaexpert.co.in Q. class Nav{ public enum Direction { NORTH, SOUTH, EAST, WEST } } public class Sprite{ // insert code here } Which code, inserted at line 14, allows the Sprite class to compile? A. Direction d = NORTH; B. Nav.Direction d = NORTH; C. Direction d = Direction.NORTH; D. Nav.Direction d = Nav.Direction.NORTH;
  • 10. OCJP www.javaexpert.co.in Q. int [] x = {1, 2, 3, 4, 5}; //Line 1 int y[] = x; // Line 2 System.out.println(y[2]); // Line 3 Which statement is true? // Line 4 A. Line 3 will print the value 2. B. Line 3 will print the value 3. C. Compilation will fail because of an error in line 1. D. Compilation will fail because of an error in line 2.