What result come when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { new R4RSCJPTest(); } public R4RSCJPTest(int i) //1 { System.out.print(" " + (i *= 2)); } public void R4RSCJPTest(long i) //2 { System.out.print(" " + i); } public R4RSCJPTest() //3 { System.out.print(" No_Argument "); } } ,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
What result come when we compile and run following code:
public class R4RSCJPTest 
{
      public static void main(String args[]) 
      {
            new R4RSCJPTest();
      }
      public R4RSCJPTest(int i)               //1
      {
            System.out.print(" " + (i *= 2));
      }
      public void R4RSCJPTest(long i)         //2 
      {
            System.out.print(" " + i);
      }
      public R4RSCJPTest()                    //3 
      {
            System.out.print(" No_Argument ");
      }
} 

More interview questions and answers

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"); } }

What benefits do we gain from encapsulation?

What is the object-oriented relationship between a tree and an oak?

What result come 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.println(" Test B"); super(); } }

What is the object-oriented relationship between a city and a road?

Invoking a Superclass Version of an Overridden Method

Select correct statements about constructor from followings:

What result come when we compile and run following code: public class R4RSCJPTest { static int x; public static void main(String args[]) { new R4RSCJPTest(8L); } public R4RSCJPTest(int i) { System.out.print(" " + (i += 3)); } public R4RSCJPTest(long i) { this(); x=(int)i; System.out.print(" " + (i)); } public R4RSCJPTest() { this(x); System.out.print(" No_Agument "); } }

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

What result come when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { new R4RSCJPTest(); } public R4RSCJPTest(int i) //1 { System.out.print(" " + (i *= 2)); } public void R4RSCJPTest(long i) //2 { System.out.print(" " + i); } public R4RSCJPTest() //3 { System.out.print(" No_Argument "); } }

Overloaded Methods

Give the list of Illegal Override Code

Legal Overloads

Invoking Overloaded Methods

Polymorphism in Overloaded and Overridden Methods

Give the list of Method Invocation Code

Give the list of Overloaded Method

Constructor Basics

Constructor Chaining

Rules for Constructors

determine if a default constructor will be created.

What happens if the super constructor has arguments?

Overloaded Constructors

Legal Return Types

Return Types on Overloaded Methods

Overriding and return types

returning a value

What benefits do you gain from encapsulation?

Select three correct code fragments that we inserted in Object test1(), doesn't give any compile time error in following code: class R4RSCJPTest { public static void main(String args[]) { R4RSCJPTest test = new R4RSCJPTest(); Object o = test.test1(); } Object test1() { //insert code here } }

Select two correct options.That when we insert in following code compile time error comes: class R4RSCJPTest { public static void main(String args[]) { int i; } long test( int i, float j) { //insert code here } }

Given the following, public class myprog { public int getHeight() { return height; } public void setHeight(int h) { height = h; } public int height; } which is true about the class described above?

Given the following, public class myprog extends programe { private int bar; public void setBar(int y) { bar = y; } } class programe { public int foo; } which is true about the classes escribed above?

Which is true?

Which two are not benefits of encapsulation?

Given the following, class Y extends X { int getID() { return id; } } class Z { public int name; } class X { Z z = new Z(); public int id; } which two are true about instances of the classes listed above?

Given the following, class X { public void baz() { System.out.println("X"); } } public class Y extends X { public static void main(String [] args) { X x = new Y(); x.baz(); } public void baz() { System.out.println("Y"); } } what is the result?

Given the following : class Foo { String doStuff(int a) { return "hello Its my programe "; } } which method would not be legal in a subclass of Foo?

Given the following, class myprog { public int doStuff(int a) { return a * 2; } } public class ChildClass extends ParentClass { public static void main(String [] args ) { ChildClass cc = new ChildClass(); long a = cc.doStuff(7); System.out.println("a = " + a); } public long doStuff(int a) { return a * 3; } } What is the result?

Given the following, class prog { .int doStuff(int x, float y) { return 7; } } class prog2 extends prog { // insert code here } which two methods, if inserted independently at line 8, will not compile?

Given the following, public class myprog { public static void main(String [] args ){ Prog p = new Subprog(); } } class Prog { public Prog() { super(); System.out.println("instantiate a prog"); } } class Subprog extends Prog { public subprog() { System.out.println("instantiate a subprog"); } } what is the result?

Given the following, public class myprog { public static void main(String [] args ){ prog p = new Subprog(); } } class Prog { public Prog() { super(); System.out.println("instantiate a prog"); } } class Subprog extends Prog { public Subprog() { System.out.println("instantiate a subprog"); super(); } } what is the result?

Given the following, class MyProg { public MyProg(int a) { System.out.println("super " + a); } } public class MySubprog extends Myprog { public MySubprog() { super(2); System.out.println("sub"); } public static void main(String [] args) { MyProg sup = new MySubprog(); } } what is the result?

Given the following, public class MyConst { public static void main(String [] args) { new MyConst(4L); } public MyConst(int a) { this(); System.out.print(" " + (a * 2)); } public MyConst(long a) { this((int) a); System.out.print(" " + a); } public MyConst() { System.out.print("no-arg "); } } what is the result?

Given the following, public class MyConst { public static void main(String [] args) { new MyConst(); } public void MyConst(int a) { System.out.print(" " + (a * 2)); } public void MyConst(long a) { System.out.print(" " + a); } public void MyConst() { System.out.print("no-arg "); } } what is the result?

Given the following, class Sporty { Sporty(String name) { } } if class Car extends Sporty, and class Car has only one constructor, which of the following could be the legal constructor for class Car?

Which two of these statements are true about constructors?

Given the following, int a; a = n.prog(); int prog() { ............................ return b; } which line of code, inserted at Dotted line, will not compile?

What result comes when we compile and run following code: class R4RSCJPTest { public static abc a = new abc(); public static xyz x1 = new xyz(); public static xyz x2; public static void main(String args[]) { for (int i=1; i<5; i++) { x2 = getxyz(i); x2.run(); } } static xyz getxyz(int j) { if ( 0 == j % 2 ) { return a; } else { return x1; } } } class abc extends xyz { void run() { System.out.print("abc "); } } class xyz { void run() { System.out.print("xyz "); }

Given the following, long test( int a, float b) { ........................... } which two of the following lines, inserted independently, at dotted line would not compile?

Given the following, import java.util.*; class myprog { public static void main(String [] args) { Myprog r = new Myprog(); Object o = r.prog(); } Object test() { ............................ ......................... } } which two of the following code fragments inserted at two dotted lines will not compile?

Given the following, import java.util.*; class myprog { public static void main(String [] args) { myprog r = new myprog(); Object o = r.prog(); } Object prog() { ................... ................... } } which two of the following code fragments inserted at two dotted lines will not compile?

Given the following, class Prog { public static Foo p = new Foo(); public static Foo p2; public static Bar y = new Bar(); public static void main(String [] args) { for (int a=0;a <6; a++) { f2 = getFooa(); f2.react(); } 11. } 12. static Foo getFoo(int b) { if ( 0 == b % 2 ) { return p; } else { return y; } } } class Bar extends Foo { void react() { System.out.print("Bar "); } } class Foo { void react() { System.out.print("Foo "); } } what is the result?

Strings Are Immutable Objects

Important Facts About Strings and Memory

Select one line of code when we insert in following code program will not compile: class R4RSCJPTest { public static void main(String args[]) { int i; R4RSCJPTest test = new R4RSCJPTest(); i = test.run(); System.out.println(i); } int run() { //insert code here return j; } }

What result come when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { R4RSCJPTest test = new R4RSCJPTest(3); test.R4RSCJPTest(0); } public R4RSCJPTest(int i) //1 { this((long) i); System.out.print(" " + (i *= 2)); } public R4RSCJPTest(long i) //2 { System.out.print(" " + i); } public void R4RSCJPTest(int i) //3 { System.out.print(" No_Argument "); } }

What result come when we try to compile and run following code: class xyz extends abc { static private int xyzCount = 0; public String xName; int xNumber; static synchronized int addxyz() { xName = My name is xyz + xyzCount; return xyzCount; } public xyz() { xNumber = addxyz(); } }

Given the following, public class Myprog { public static void main(String [] args) { String a1 = "abc"; String a2 = "def"; String a3 = a2; a2 = "ghi"; System.out.println(a1 + a2 + a3); } } what is the result?

Given the following, String a = "abc"; a.toUpperCase(); String a = a.replace('B', 'b'); b = b + "xyz"; System.out.println(b); what is the result?

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