Submitted by c-admin on Mon, 05/27/2019 - 22:48
Consider the following two classes (in the same package but defined in different source files):
public class Square {
double side = 0;
double area;
public Square(double length){ this.side = length; }
public double getSide() { return side; }
public void setSide(double side) { this.side = side; }
double getArea() { return area; }
}
public class TestClass {
public static void main(String[] args) throws Exception {
Square sq = new Square(10.0);
sq.area = sq.getSide()*sq.getSide();
System.out.println(sq.getArea());
} }
You are assigned the task of refactoring the Square class to make it better in terms of encapsulation. What changes will you make to this class?
Select 2 options
A. Make setSide() method private.
B. Make getArea() method private.
C. Make side and area fields private.
D. Make the side field private and remove the area field.
E. Change getArea method to:
public double getArea(){ return side*side; }
F. Add a setArea() method.
Submitted by c-admin on Mon, 05/27/2019 - 22:43
Which of the given options can be successfully inserted at line 1....
//line 1
public class A{
}
Select 3 options
A. import java.lang.*;
B. package p.util;
C. public class MyClass{ }
D. abstract class MyClass{ }
Submitted by c-admin on Mon, 05/27/2019 - 22:39
When a class whose members should be accessible only to members of that class is coded such a way that its members are accessible to other classes as well, this is called ...
Select 1 option
A. strong coupling
B. weak coupling
C. strong typing
D. weak encapsulation
E. weak polymorphism
F. high cohesion
G. low cohesion
Submitted by c-admin on Mon, 05/27/2019 - 22:37
What will be the output of the following program when it is compiled and run with the command line
java TestClass 1 2 3
public class TestClass {
public static void main(String[] args) {
System.out.println("Values : "+args[0]+args[1]);
}
}
Select 1 option
A. Values: java TestClass
B. Values: TestClass 1
C. Values: 12
D. Values: 23
E. Values: 3
Submitted by c-admin on Mon, 05/27/2019 - 22:27
Which of the following are valid declarations of the standard main() method?
Select 2 options
A. static void main(String args[ ]) { }
B. public static int main(String args[ ]) {}
C. public static void main (String args) { }
D. final static public void main (String[ ] arguments ) { }
E. public static void main (String[ ] args) { }
Pages