The main method should be static for the reason
The main method should be static for the reason
Which of the following options is the best for generating random integer 0 or 1?
Which of the following options is the best for generating random integer 0 or 1?
Given the following piece of code:
class Person{
public int number;
}
public class Test{
public void doIt(int i , Person p){
i = 5;
p.number = 8;
}
public static void main(String args[]){
int x = 0;
Person p = new Person();
new Test().doIt(x, p);
System.out.println(x + " " + p.number);
}
}
What is the result?
Given the following piece of code:
class Person{
public int number;
}
public class Test{
public void doIt(int i , Person p){
i = 5;
p.number = 8;
}
public static void main(String args[]){
int x = 0;
Person p = new Person();
new Test().doIt(x, p);
System.out.println(x + " " + p.number);
}
}
What is the result?
Determine output of the following program.
public class Test{
public static void main(String args[]){
System.out.println( Math.floor( Math.random( ) ) ) ;
}
}
Determine output of the following program.
public class Test{
public static void main(String args[]){
System.out.println( Math.floor( Math.random( ) ) ) ;
}
}
What is the expected output?
public class Profile {
private Profile(int w) {
System.out.print(w);
}
public final Profile() {
System.out.print(10);
}
public static void main(String args[]) {
Profile obj = new Profile(50);
}
}
What is the expected output?
public class Profile {
private Profile(int w) {
System.out.print(w);
}
public final Profile() {
System.out.print(10);
}
public static void main(String args[]) {
Profile obj = new Profile(50);
}
}
Which of the following statements regarding static methods are correct?
1. Static methods are difficult to maintain, because you can not change their implementation.
2. Static methods can be called using an object reference to an object of the class in which this method is defined.
3. Static methods are always public, because they are defined at class-level.
4. Static methods do not have direct access to non-static methods which are defined inside the same class.
Which of the following statements regarding static methods are correct?
1. Static methods are difficult to maintain, because you can not change their implementation.
2. Static methods can be called using an object reference to an object of the class in which this method is defined.
3. Static methods are always public, because they are defined at class-level.
4. Static methods do not have direct access to non-static methods which are defined inside the same class.
What will be the result of compiling and running the given code?
class A{
int b=10;
private A(){
this.b=7;
}
int f(){
return b;
}
}
class B extends A{
int b;
}
public class Test{
public static void main(String[] args){
A a = new B();
System.out.println(a.f());
}
}
What will be the result of compiling and running the given code?
class A{
int b=10;
private A(){
this.b=7;
}
int f(){
return b;
}
}
class B extends A{
int b;
}
public class Test{
public static void main(String[] args){
A a = new B();
System.out.println(a.f());
}
}
class MyClass{
int i;
int j;
public MyClass(int i, int j){
this.i = i;
this.j = j;
}
public void call(){
System.out.print("One");
}
}
public class Test{
public static void main(String args[]){
MyClass m = new MyClass();
m.call();
}
}
class MyClass{
int i;
int j;
public MyClass(int i, int j){
this.i = i;
this.j = j;
}
public void call(){
System.out.print("One");
}
}
public class Test{
public static void main(String args[]){
MyClass m = new MyClass();
m.call();
}
}
Determine Output:
class A{
public static void method(int i){
System.out.print("Method 1");
}
public static int method(String str){
System.out.print("Method 2");
return 0;
}
}
public class Test{
public static void main(String args[]){
A.method(5);
}
}
Determine Output:
class A{
public static void method(int i){
System.out.print("Method 1");
}
public static int method(String str){
System.out.print("Method 2");
return 0;
}
}
public class Test{
public static void main(String args[]){
A.method(5);
}
}
In which area of memory, the system stores parameters and local variables whenever a method is invoked?
In which area of memory, the system stores parameters and local variables whenever a method is invoked?
The finalize() method is called just prior to
The finalize() method is called just prior to
What is the output of the program?
class Test{
public int display(int x, int y){
return ("The sum of x and y is " + x + y);
}
public static void main(String args[]){
Test test = new Test();
System.out.println(test.display(4,5));
}
}
What is the output of the program?
class Test{
public int display(int x, int y){
return ("The sum of x and y is " + x + y);
}
public static void main(String args[]){
Test test = new Test();
System.out.println(test.display(4,5));
}
}
For the above class(MyClass) what is the correct way of declaring constructor?
For the above class(MyClass) what is the correct way of declaring constructor?
What is Math.floor(3.6)?
What is Math.floor(3.6)?
What is the output for the below code ?
class A{
public A(){
System.out.println("A");
}
public A(int i){
this();
System.out.println(i);
}
}
class B extends A{
public B(){
System.out.println("B");
}
public B(int i){
this();
System.out.println(i+3);
}
}
public class Test{
public static void main (String[] args){
new B(5);
}
}
What is the output for the below code ?
class A{
public A(){
System.out.println("A");
}
public A(int i){
this();
System.out.println(i);
}
}
class B extends A{
public B(){
System.out.println("B");
}
public B(int i){
this();
System.out.println(i+3);
}
}
public class Test{
public static void main (String[] args){
new B(5);
}
}
class A{
A(String s){}
A(){}
}
1. class B extends A{
2. B(){}
3. B(String s){
4. super(s);
5. }
6. void test(){
7.
8. }
9. }
Which of the below code can be insert at line 7 to make clean compilation ?
class A{
A(String s){}
A(){}
}
1. class B extends A{
2. B(){}
3. B(String s){
4. super(s);
5. }
6. void test(){
7.
8. }
9. }
Which of the below code can be insert at line 7 to make clean compilation ?
The variables declared in a class for the use of all methods of the class are called
The variables declared in a class for the use of all methods of the class are called
What is the prototype of the default constructor?
What is the prototype of the default constructor?
What is the expected output?
public class Profile {
private Profile(int w) {
System.out.print(w);
}
public static Profile() {
System.out.print (10);
}
public static void main(String args[]) {
Profile obj = new Profile(50);
}
}
What is the expected output?
public class Profile {
private Profile(int w) {
System.out.print(w);
}
public static Profile() {
System.out.print (10);
}
public static void main(String args[]) {
Profile obj = new Profile(50);
}
}
What is the expected output?
class Animal {
Animal() {
System.out.println("Animal");
}
}
class Wild extends Animal{
Wild() {
System.out.println("Wild");
super();
}
}
public class Test {
public static void main(String args[]) {
Wild wild = new Wild();
}
}
What is the expected output?
class Animal {
Animal() {
System.out.println("Animal");
}
}
class Wild extends Animal{
Wild() {
System.out.println("Wild");
super();
}
}
public class Test {
public static void main(String args[]) {
Wild wild = new Wild();
}
}
Determine output:
public class Test{
public static void main(String args[]){
MyClass obj = new MyClass();
obj.val = 1;
obj.call(obj);
System.out.println(obj.val);
}
}
class MyClass{
public int val;
public void call(MyClass ref){
ref.val++;
}
}
Determine output:
public class Test{
public static void main(String args[]){
MyClass obj = new MyClass();
obj.val = 1;
obj.call(obj);
System.out.println(obj.val);
}
}
class MyClass{
public int val;
public void call(MyClass ref){
ref.val++;
}
}
What is the output of the above program ?
class Num {
Num(double x ){
System.out.println( x ) ;
}
}
public class Test extends Num {
public static void main(String[] args){
Num num = new Num( 2 ) ;
}
}
What is the output of the above program ?
class Num {
Num(double x ){
System.out.println( x ) ;
}
}
public class Test extends Num {
public static void main(String[] args){
Num num = new Num( 2 ) ;
}
}
class MyClass{
MyClass(){
System.out.print("one");
}
public void myMethod(){
this();
System.out.print("two");
}
}
public class TestClass{
public static void main(String args[]){
MyClass obj = new MyClass();
obj.myMethod();
}
}
class MyClass{
MyClass(){
System.out.print("one");
}
public void myMethod(){
this();
System.out.print("two");
}
}
public class TestClass{
public static void main(String args[]){
MyClass obj = new MyClass();
obj.myMethod();
}
}
What will be the output?
public class Test{
public static void main(String[] args){
String value = "abc";
changeValue(value);
System.out.println(value);
}
public static void changeValue(String a){
a = "xyz";
}
}
What will be the output?
public class Test{
public static void main(String[] args){
String value = "abc";
changeValue(value);
System.out.println(value);
}
public static void changeValue(String a){
a = "xyz";
}
}
Which of these is a legal definition of a method named examveda assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer.
Which of these is a legal definition of a method named examveda assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer.
What is the output for the below code?
public class Test{
public static void printValue(int i, int j, int k){
System.out.println("int");
}
public static void printValue(byte...b){
System.out.println("long");
}
public static void main(String... args){
byte b = 9;
printValue(b,b,b);
}
}
What is the output for the below code?
public class Test{
public static void printValue(int i, int j, int k){
System.out.println("int");
}
public static void printValue(byte...b){
System.out.println("long");
}
public static void main(String... args){
byte b = 9;
printValue(b,b,b);
}
}
The following code contains one compilation error, find it?
public class Test {
Test() { }
static void Test() { this(); }
public static void main(String[] args) {
Test();
}
}
The following code contains one compilation error, find it?
public class Test {
Test() { }
static void Test() { this(); }
public static void main(String[] args) {
Test();
}
}
What will be the return type of a method that not returns any value?
What will be the return type of a method that not returns any value?
The implicit return type of a constructor is
The implicit return type of a constructor is
Which of the modifier can't be used for constructors?
Which of the modifier can't be used for constructors?
What is the output for the below code ?
1. public class A{
2. int add(int i, int j){
3. return i+j;
4. }
5. }
6. public class B extends A{
7. public static void main(String argv[]){
8. short s = 9;
9. System.out.println(add(s,6));
10. }
11.}
What is the output for the below code ?
1. public class A{
2. int add(int i, int j){
3. return i+j;
4. }
5. }
6. public class B extends A{
7. public static void main(String argv[]){
8. short s = 9;
9. System.out.println(add(s,6));
10. }
11.}