Set 9

Multiple Choice Question

QID: 
459

What will the following code print when run?

class A{
String value = "test"; A(String val){
this.value = val;
}
}
public class TestClass {
public static void main(String[] args) throws Exception { 
new A("new test").print();
}
}

Select 1 option

A. test
B. new test
C. It will not compile.
D. It will throw an exception at run time.

Multiple Choice Question

QID: 
458

Given:

class Triangle{    
public int base;    
public int height;    
public double area = 0;        
public Triangle(int base, int height){        
this.base = base; 
this.height = height;        
updateArea();    }    
public void updateArea(){        
double a = base*height/2;        
area = a;    }    
public void setBase(int b){
 base  = b; updateArea(); }    
public void setHeight(int h){ 
height  = h; 
updateArea(); } } 

Which variables are not accessible from anywhere within given class code (except from where they are declared)?

Select 1 option 

A. base, height, area 
B. area, b, h 
C. base, height 
D. b, h, a

Multiple Choice Question

QID: 
457

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

public class TestClass{
static int si = 10;
public static void main (String args[]){
new TestClass();
}
public TestClass(){
System.out.println(this);
}
public String toString(){
return "TestClass.si = "+this.si;
}   }

Select 1 option

A. The class will not compile because you cannot override toString() method.
B. The class will not compile as si being static, this.si is not a valid statement.
C. It will print TestClass@nnnnnnnn, where nnnnnnn is the hash code of the TestClass object referred to by 'this'.
D. It will print TestClass.si = 10;
E. None of the above.

Multiple Choice Question

QID: 
456

Consider the following code appearing in the same file:

class Data {
private int x = 0, y = 0;
public Data(int x, int y){
this.x = x; this.y = y;
}
}public class TestClass {
public static void main(String[] args) throws Exception {
Data d = new Data(1, 1);        //add code here
}
}

Which of the following options when applied individually will change the Data object currently referred to by the variable d to contain 2, 2 as values for its data fields?

Select 1 option

A. Add the following two statements :
          d.x = 2;
          d.y = 2;
B. Add the following statement:
           d = new Data(2, 2);
C. Add the following two statements:
        d.x += 1;
         d.y += 1;
D. Add the following method to Data class:
         public void setValues(int x, int y){
         this.x.setInt(x); this.y.setInt(y);
         }
                 Then add the following statement:
                  d.setValues(2, 2);
E. Add the following method to Data class:
           public void setValues(int x, int y){
          this.x = x; this.y = y;
                         }
            Then add the following statement:
                 d.setValues(2, 2);

Multiple Choice Question

QID: 
455

What will the following class print when compiled and run?

class Holder{
int value = 1;
Holder link;
public Holder(int val){ this.value = val; }
public static void main(String[] args){
final Holder a = new Holder(5);
Holder b = new Holder(10);
a.link = b;
b.link = setIt(a, b);
System.out.println(a.link.value+" "+b.link.value);
}
public static Holder setIt(final Holder x, final Holder y){
x.link = y.link;
return x;
}
}

Select 1 option

A. It will not compile because 'a' is final.
B. It will not compile because method setIt() cannot change x.link.
C. It will print 5, 10.
D. It will print 10, 10.
E. It will throw an exception when run.

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (52) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (4) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (7) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (8) Javascript Frameworks (1) Java SE Professional (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quizzes (17) references (2) resources (1) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (1) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)