Java OOPs Quiz - SCJP
Description: Java OOPs Quiz - SCJP | |
Number of Questions: 10 | |
Created by: Aliensbrain Bot | |
Tags: java scjp |
Attempted
0/10
Correct 0
Score 0
‹
›
Which statement is true for the following code?
public class Plant {
private String name;
public Plant(String name) { this.name = name; }
public String getName() { return name; }
}
public class Tree extends Plant {
public void growFruit() { }
public void dropLeaves() { }
}
What will the result for following code?
public class Yikes {
public static void go(Long n) {System.out.println("Long ");}
public static void go(Short n) {System.out.println("Short ");}
public static void go(int n) {System.out.println("int ");}
public static void main(String [] args) {
short y = 6;
long z = 7;
go(y);
go(z);
}
}
Which two statements are true about has-a and is-a relationships?
Which two, independently, will allow Sub to compile?
1. class Super {
2. private int a;
3. protected Super(int a) { this.a = a; }
4. }
...
11. class Sub extends Super {
12. public Sub(int a) { super(a); }
13. public Sub() { this.a = 5; }
14. }
What will be the output?
public class Base {
public static final String FOO = "foo";
public static void main(String[] args) {
Base b = new Base();
Sub s = new Sub();
System.out.print(Base.FOO);
System.out.print(Sub.FOO);
System.out.print(b.FOO);
System.out.print(s.FOO);
System.out.print(((Base)s).FOO);
}
}
class Sub extends Base {
public static final String FOO="bar";
}
Which two statements are true?
What is the output?
public class Wow {
public static void go(short n) {System.out.println("short");}
public static void go(Short n) {System.out.println("SHORT");}
public static void go(Long n) {System.out.println(" LONG");}
public static void main(String [] args) {
Short y = 6;
int z = 7;
go(y);
go(z);
}
}
Which statement is true
public class CreditCard {
private String cardID;
private Integer limit;
public String ownerName;
public void setCardInformation(String cardID,
String ownerName,
Integer limit) {
this.cardID = cardID;
this.ownerName = ownerName;
this.limit = limit;
}
}
What is the output?
interface TestA { String toString(); }
public class Test {
public static void main(String[] args) {
System.out.println(new TestA() {
public String toString() { return "test"; }
});
}
}
Which three methods, inserted individually at line 14, will correctly complete class Two?
class One {
void foo() { }
}
class Two extends One {
//insert method here
}