Compiling with Code That Uses Assert as an Identifier ,Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher
Compiling with Code That Uses Assert as an Identifier

If we don\'t use the -source 1.4 flag, then the default behavior is as though we said to the compiler, Compile this code as if we didn\'t known anything about assert as a keyword, so that I may use the word assert as an identifier for a method or variable.

More interview questions and answers

What result come when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int i = 3; do while ( i < 3 ) System.out.print("Value of i is " + i); while ( i > 3 ) ; } }

What result come when we compile and run following code: class R4RSCJPTest { static int i; public static void main(String [] args) { R4RSCJPTest test = new R4RSCJPTest(); test.start(); System.out.println(i); } void start() { int j = 3; foo(j); j = j^2; System.out.print(j + " "); } void foo(int j) { j = j*2; i = j; } }

What result come when we compile and run following code: public class R4RSCJPTest { static boolean boo1, boo2; public static void main(String [] args) { int i = 0; if ( !boo1 ) { if ( !boo2 ) { boo1 = false; i++; if ( 0 < i ) { i++; } boo2 = !boo2; if ( boo1 ) i = i + 10; else if ( boo2 == false ) i = i + 100; else if ( boo1 | boo2 ) i = i + 1000; } } System.out.println(i); } }

Writing Code Using if statement

legal arguments for if Statements

Writing Code Using Switch Statement

Legal Arguments to switch and case

default, break, and fall-through in switch blocks

The Default Case

creating a switch-case statement.

Select correct data types that we used in switch statements.

Select two correct for loops when we insert those in following code output will be like that: i = 0 i = 1 class R4RSCJPTest { public static void main(String args[]) { //insert both for loop here { System.out.println("i = "+ i); } } }

What result come when we compile and run following code: class R4RSCJPTest { public static void main(String args[]) { int i = 2; boolean boo = false; outer: while (!boo) { i++; inner: for (int j = 1; j < 7; j++) { i += j; if (j == 4) continue inner; break outer; } continue outer; } System.out.println("Value of i is " +i); } }

What result come when we compile and run following code: class R4RSCJPTest { public static void main(String args[]) { int i = 9; label: if (i > 3) { i--; continue label; } System.out.println("i is " + i); } }

What result come when we compile and run following code: class R4RSCJPTest { public static void main(String args[]) { int i = 9; label: while (i > 3) { i--; continue label; } System.out.print("i is " + i); } }

Writing code using loops.

Using while loops

Using do-while Loops

Using for Loops

Declaration and Initialization

Conditional (boolean) Expression

What result come when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { try { System.out.print("Welcome"); } finally { System.out.println("Finally executing "); } } }

Iteration Expression

for Loop Issues

Using break and continue in for Loops

Unlabeled Statements

Labeled Statements

Creating a Labeled while Loop

What result come when we compile and run following code: import java.io.*; public class R4RSCJPTest { public static void main(String args[]) { FileOutputStream out = null; try { out = new FileOutputStream("R4R.txt"); out.write(100); } catch(IOException io) { System.out.println("IOException occur"); } finally { out.close(); } } }

What result come when we compile and following code: public class R4RSCJPTest { public static void throwit() { throw new RuntimeException(); } public static void main(String args[]) { try { System.out.println("Welcome "); throwit(); System.out.println("Execute statement under try block "); } finally { System.out.println("Finally executing "); } } }

What result come when we compile and run following code: public class R4RSCJPTest { public static void throwit () { System.out.print("throwit "); throw new RuntimeException(); } public static void main(String [] args) { try { System.out.print("Welcome "); throwit(); } catch (Exception e ) { System.out.print("exception caught "); } finally { System.out.print("finally executed "); } System.out.println("user "); } }

Handling Exceptions

Catching an Exception Using try and catch

Using finally

Propagating Uncaught Exceptions

Propagating and Catching an Exception

Defining Exceptions

Exception Hierarchy

Handling an Entire Class Hierarchy of Exceptions

Exception Matching

Exception Declaration and the Public Interface

Rethrowing the Same Exception

Creating an Exception

Working with the Assertion Mechanism

Assertions Overview

Assertion Expression Rules

Enabling Assertions

Compiling with Assertions

Compiling Assertion-Aware Code

Compiling with Code That Uses Assert as an Identifier

Running with Assertions

Enabling Assertions at Runtime

Disabling Assertions at Runtime

Selective Enabling and Disabling

Using Assertions Appropriately

Do not use assertions to validate arguments to a public method.

Do use assertions to validate arguments to a private method.

Do not use assertions to validate command-line arguments.

Do use assertions, even in public methods, to check for cases that you know are never, ever supposed to happen

Do not use assert expressions that can cause side effects!

Select correct option for the following code: public class Vehicle { // Write here Vehicle code } public class Bike extends Vehicle { // Write here Cool Bike code } public class Hayabusa extends Bike { // Write here some specific information of Hayabusa // Keep in mind Hayabusa inherits accessible Bike members }

Which is the correct object-oriented relationship between a Building and a Apartment.

Select the three correct option in case of Method overriding.

Select two correct options from the followings:

Select three correct options from the followings:

What result comes when we compile and run following code: class Vehicle { } class Bike extends Vehicle { } class TestVehicles { public void ABC(Vehicle v) { System.out.println("Vehicle"); } public void ABC(Bike b) { System.out.println("Bike"); } public static void main (String [] args) { TestVehicles uvobj = new TestVehicles(); Vehicle vObj = new Vehicle(); Bike bObj = new Bike(); uvobj.ABC(vObj); uvobj.ABC(bObj); } }

What result comes when we compile and run following code: class Vehicle { } class Bike extends Vehicle { } class TestVehicles { public void ABC(Vehicle v) { System.out.print("Vehicle"); } public void ABC(Bike b) { System.out.println(" Bike"); } public static void main (String [] args) { TestVehicles uvobj = new TestVehicles(); Vehicle vObj = new Vehicle(); Vehicle VRTB = new Bike(); //VRTB(Vehicle refer to Bike) uvobj.ABC(VRTB); } }

Given the following, public class myprog { final static short a = 2; public static in b = 0; public static void main(String [] args) { for (int c=0; c < 3; c++) { switch (c) { case b: System.out.print("0 "); case a-1: System.out.print("1 "); case a: System.out.print("2 "); } } } } what is the result ?

Given the following, public class myprog { final static short a = 2; public static int b = 0; public static void main(String [] args) { for (int c=0; c < 3; c++) { switch (c) { case a: System.out.print("0 "); case a-1: System.out.print("1 "); case a-2: System.out.print("2 "); } } } what is the result?

Select three corerct options from the following:

Given the following, public class If1 { static boolean b; public static void main(String [] args) { short hand = 42; if ( hand < 50 & !b ) hand++; if ( hand > 50 ) ; else if ( hand > 40 ) { hand += 7; hand++; } lse -hand; System.out.println(hand); . } what is the result

Select two correct options incase of default constructor.

Given the following, public class myprog { final static short a = 2; public static int b = 0; public static void main(String [] args) { for (int c=0; c < 4; c++) { switch (c) { case a: System.out.print("0 "); default: System.out.print("def "); case a-1: System.out.print("1 "); break; case a-2: System.out.print("2 "); } } } } what is the result?

Given the following, public class myprog { static boolean x1, x2; public static void main(String [] args) { int a = 0; if ( !x1 ) { if ( !x2 ) { x1 = true; a++; if ( 5 > 6 ) { ++; if ( !x1 ) a = a + 10; else if ( x2 = true ) a = a + 100; else if ( x1 | x2 ) a = a + 1000; } } System.out.println(a); } what is the result?

Given the following, public class myprog { public void loop() { int a= 0; while ( 1 ) { System.out.print("a plus one is " + (a + 1)); } } } Which statement is true?

Given the following, class myprog { public void test() { ---------------------------- System.out.println("a = "+ a); } } } and the following output, a = 0 a = 1 which two lines of code (inserted independently) will cause this output?

Given the following, public class Test { public static void main(String [] args) { int A = 1; do while ( A < 1 ) System.out.print("A is " + A); while ( A > 1 ) ; } } what is the result?

Given the following, int A = 0; uter: while (true) { A++; inner: for (int b = ; b < 10; b++) { Self Test 67 A += b; if (b == 3) continue inner; break outer; } continue outer; } System.out.println(I); what is the result?

Given the following, int x = 0; label: if (x < 2) { System.out.print("x is " + x); x++; continue label; } what is the result?

Given the following, System.out.print("Open "); try { System.out.print("Hello This is my first Exception programe "); throw new FileNotFoundException(); } System.out.print(" Catch Here "); catch(EOFException e) { System.out.print("EOF exception"); } catch(FileNotFoundException e) { System.out.print("File not found"); } And given that EOFException and FileNotFoundException are both subclasses of IOException, and further assuming this block of code is placed into a class, which statement is most true concerning this code?

What result come when we compile and run following code: class Test { public void foo() { System.out.println("Basic Info"); } } public class R4RSCJPTest extends Test { public static void main(String args[]) { Test t = new R4RSCJPTest(); t.foo(); } public void foo() { System.out.println("Check your skill with R4RSCJPTest"); } }

What result come when we compile and run following code: class Parent { public int foo(int l) { return l * 5; } } public class Child extends Parent { public static void main(String args[] ) { Child c = new Child(); long l = c.foo(6); System.out.println("l is " + l); } public long foo(int l) { return l * 4; } }

Given the following, public class MyProg { public static void main(String args[]){ try { System.out.print("WELCOME TO MY WORLD "); } finally { System.out.println("Finally executing "); } } } what is the result?

Given the following, import java.io.*; public class MyProgram { public static void main(String args[]){ FileOutputStream out = null; try { out = new FileOutputStream("test.txt"); out.write(122); } catch(IOException io) { System.out.println("IO Error."); } finally { out.close(); } } } and given that all methods of class FileOutputStream, including close(), throw an IOException, which of these is true?

Given the following, public class MyProg{ public static void throwit() { throw new RuntimeExcep(); } public static void main(String args[]){ try { System.out.println("Hello welcome to my world "); throwit(); System.out.println("Done with try block "); } finally { System.out.println("Finally executing "); } } } which answer most closely indicates the behavior of the program?

Given the following, public class RTExcept { public static void throwit () { System.out.print("throwit "); throw new RuntimeException(); } public static void main(String [] args) { try { System.out.print("hello "); throwit(); } atch (Exception re ) { System.out.print("caught "); } finally { System.out.print("finally "); } System.out.println("after "); } } what is the result

Select correct options to describe the following code: public class R4RSCJPTest { public int getSize() { return size; } public void setSize(int s) { size = s; } public int size; }

Which of the following statements is true?

Which two of the following statements are true?

Given the following, public class Test { public static int b; public static void foo(int a) { System.out.print("foo "); b = a; } public static int bar(int c) { System.out.print("bar "); return b = c; } public static void main(String [] args ) { int x = 0; assert x > 0 : bar(7); assert x > 1 : foo(8); System.out.println("done "); } } what is the result?

Which two of the following statements are true?

Given the following, public class myprog { public static int a; public static int foo(int b) { return b * 2; } public static void main(String [] args) { int c = 5; assert c > 0; assert c > 2: foo(c); if ( c < 7 ) assert c > 4; switch (c) { case 4: System.out.println("4 "); case 5: System.out.println("5 "); default: assert c < 10; } if ( c < 10 ) assert c > 4: c++; System.out.println(c); } } which line is an example of incorrectly use of assertions?

Select correct option to describe the following code: class Test { public int foo; } public class R4RSCJPTest extends Test { private int boo; public void setBoo(int b) { boo = b; } }

Benefits of Encapsulation

Select correct options from the followings:

IS-A Relationships

HAS-A Relationship

Overridden Methods

Select correct advantages of encapsulation from the followings:

What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { A a = new B(); } } class A { public A() { super(); System.out.println("Test A"); } } class B extends A { public B() { System.out.print("Test B"); } }

R4R provides free online tutolrails ,examples for Freshers and experts .We cover core java, tutorials, spring, Hibernate, python, struts, struts 2,c language, spring boot,PHP,MYSQL,C#,ASP.NET,WPF,WCF,Photoshop , JSP, programming, example, Interview questions and answer