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?,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
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?

More interview questions and answers

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?

Given the following, String a = new String("abc"); b = "xyz"; a = a + b; how many String objects have been created?

Given the following, String x = "Books"; x = x.substring(5,7); char y = x.charAt(1); x = x + y; System.out.println(x); what is the result?

Given the following, String s = "bookpaper"; s.substring(1,7);s = "w" + s; s.append("woo"); System.out.println(s); what is the result?

Given the following, public class Example { public static void main(String [] args) { double values[] = {-2.3, -1.0, 0.25, 4}; int cnt = 0; for (int x=0; x < values.length; x++) { if (Math.round(values[x] + .5) == Math.ceil(values[x])) { ++cnt; } } System.out.println("same results " + cnt + " time(s)"); } } what is the result?

Which of the following are valid calls to Math.max?

What two statements are true about the result obtained from calling Math.random()?

Given the following, public class myprog { public static void main(String [] args) { double value = -9.0; System.out.println( Math.sqrt(value)); } } what is the result?

Given the following, public class Degrees { public static void main(String [] args) { System.out.println( Math.sin(75) ); System.out.println( Math.toDegrees(Math.sin(75) )); System.out.println( Math.sin(Math.toRadians(75) )); System.out.println( Math.toRadians(Math.sin(75) )); } } at what line will the sine of 75 degrees be output?

Given the following, public class Wrapprog { public static void main(String [] args) { Long y = new Long(42); int a = Integer.valueOf("345"); int a2 = (int) Integer.parseInt("345", 8); int a3 = Integer.parseInt(42); int a4 = Integer.parseInt("42"); int a5 = y.intValue(); } } which two lines will cause compiler errors?

Given the following, public class NFE { public static void main(String [] args) { String s = "42"; try { s = s.concat(".5"); double d = Double.parseDouble(s); s = Double.toString(d); int x = (int) Math.ceil(Double.valueOf(s).doubleValue()); System.out.println(x); } catch (NumberFormatException e) { System.out.println("bad number"); } } } what is the result?

Given the following, public class BoolProg { public static void main(String [] args) { Boolean x1 = new Boolean("false"); boolean x2; x2 = x1.booleanValue(); if (!x2) { x2 = true; System.out.print("a "); } if (x1 & x2) { System.out.print("b "); } System.out.println("c"); } } what is the result?

Select one correct line of code that we insert in following code, program compile and run sucessfully: class Base { public Base(int a) { } } public class Test extends Base { public static void main(String arg[]) { Test t = new Test(7); } Test(int a) { super(a); } Test(String str, int a) { this(a); //Write statement here } }

Given the following, public class WrapProg { public static void main(String [] args) { Long y = new Long(42); int a = Integer.valueOf("345"); int a2 = (int) Integer.parseInt("345", 8); int a3 = Integer.parseInt(42); int a4 = Integer.parseInt("42"); int a5 = b.intValue(); } } which two lines will cause compiler errors?

Given the following, public class WrapProg { public static void main(String [] args) { String a = "98.6"; // insert code here } } which three lines inserted independently at line 4 will cause compiler errors?

Given the following, try { Float f1 = new Float("3.0"); int a = f1.intValue(); byte y = f1.byteValue(); double d = f1.doubleValue(); System.out.println(a + y + d); catch (NumberFormatException e) { System.out.println("bad number"); } what is the result?

Given the following, public class Wrapprog { public static void main(String [] args) { int result = 0; short s = 42; Long a = new Long("42"); Long b = new Long(42); Short c = new Short("42"); Short a2 = new Short(s); Integer b2 = new Integer("42"); Integer c2 = new Integer(42); if (a == b) result = 1; if (a.equals(b) ) result = result + 10; if (a.equals(b) ) result = result + 100; if (a.equals(a2) ) result = result + 1000; if (a.equals(c2) ) result = result + 10000; System.out.println("result = " + result); } } what is the result?

What result come when we compile and run following code: class Test { Test(String s) { System.out.println("String will print"); } Test(Object o) { System.out.println("Object will print"); } Test(char c) { System.out.println("character will print"); } } class R4RSCJPTest { public static void main(String arg[]) { Test t=new Test(null); } }

Given the following, public class BoolProg { public static void main(String [] args) { int result = 0; Boolean a1 = new Boolean("TRUE"); Boolean a2 = new Boolean("true"); Boolean a3 = new Boolean("tRuE"); Boolean a4 = new Boolean("false"); if (a1 == a2) result = 1; if (a1.equals(a2) ) result = result + 10; if (a2 == a4) result = result + 100; if (a2.equals(a4) ) result = result + 1000; if (a2.equals(a3) ) result = result + 10000; System.out.println("result = " + result); } } what is the result?

Given the following, public class ObjProg { public static void main(String [] args ) { int result = 0; ObjProg op = new Objprog(); Object o = op; if (o == op) result = 1; if (o != op) result = result + 10; if (o.equals(op) ) result = result + 100; if (oc.equals(o) ) result = result + 1000; System.out.println("result = " + result); } } what is the result?

Which two statements are true about wrapper or String classes?

What result come when we compile and run following code: class Test { Test(String str) { System.out.println("String will print"); } Test(StringBuffer strbuf) { System.out.println("StringBuffer will print"); } Test(Object obj) { System.out.println("Object will print"); } } class R4RSCJPTest { public static void main(String arg[]) { Test t=new Test(null); } }

What result come when you try to compile this code: public int Test (String str) { try { String abc = Str.substring(0, Str.indexOf(‘,’)); return Integer.parseInt(abc); } catch (NumberFormatException e) { System.out.println(“Error in ” + abc); } return –1; }

What result come we compile and run following code: public class Child extends Parent { public static int run(int i) { return 8; } public static void main(String[] args) { Parent p = new Child(); System.out.println(p.run(5)); } } class Parent { public static int run(int i) { return 14; } }

What result come when we compile and run following code: class Parent { public Parent(int i) { i *= 5; System.out.println("Parent " + i); } } public class Child extends Parent { public Child(int i) { super(4); i += 15; System.out.println("Child " + i); } public static void main(String args[]) { Parent p = new Child(5); } }

What result come when we compile and run following code: class Parent { } class Child1 extends Parent { } class Child2 extends Parent { } public class R4RSCJPTest { public static void main(String args[]) { Parent p = new Parent(); Child2 c = (Child2) p; } }

What result come when we compile and run following code: class Parent { } class Child extends Parent { public String run() { String name = "Vivek"; return name; } } public class R4RSCJPTest { public static void main(String args[]) { Parent p = new Child(); System.out.println(p.run()); } }

What result come when we compile and run following code: class Parent { } class Child extends Parent { public String run() { String name = "Vivek"; return name; } } public class R4RSCJPTest { public static void main(String args[]) { Parent p = new Child(); System.out.println(((Child)p).run()); } }

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