You are not logged in.

#1 2015-06-15 08:12:50

husnain
User RankUser RankUser RankUser RankUser RankUser Rank
Administrator
From: Chichawatni,Pakistan
Registered: 2014-10-03
Posts: 8,129
Website

Compile Error:

Java Quizzes Java Language Access Control And Declaration

Directions:
public class Tester{
    static int x = 4;
    public Tester(){
        System.out.print(this.x); // line 1
        Tester();
    }
    public static void Tester(){ // line 2
        System.out.print(this.x); // line 3
    }
    public static void main(String... args){ // line 4
        new Tester();
    }
}

Question:
What is the result of compiling and running the following code?

Option A):
Compile error at line 4 (invalid argument type for method main )
Option B):
Compile error at line 1 (static x must be only accessed inside static methods)
Option C):
Compile error at line 2 (constructors can't be static)
Option D):
Compile error at line 3 (static methods can't invoke this)

Correct Answer is Option D):
Compile error at line 3 (static methods can't invoke this)


You cannot discover the new oceans unless you have the courage to lose the sight of the shore.

2015-06-15 08:12:50

Advertisement
Ads By Google

Re: Compile Error:



\n

Board footer