Class SCJP  MCQ!

I came accors a SCJP MCQ that is
Which of the following statements are true?
A) A local class can be declared as abstract
B) An abstract class can be instantiated
C) An abstract class can be implicitly final
D) An abstract class must declare at least one abstract method
E) An abstract class cannot extend a concrete class
I think the answer is A only.I know that B is wrong because abstract class can not be instantiated.Is my answer is corect or not.If not can anyone give me a explanation.

A,D and E can all be straightforwardly checked. If
you have a problem with them post code, results and
question.
As far as B and C are concerned, I'm not sure about
the jargon. What is an "implicitly final" class?
When you talk about instantiating a class, does the
following count as instantiating both AbstractClass
and ConcreteImplementation?AbstractClass foo =
new ConcreteImplementation();
Still I don't get it how u got D and E as correct.
D says that an abstract class must at least declaire at least one abstract method but i think because u made a class abstract u don't need to say abstract modifier in method because it will be default.
E says abstract class can not extend a concrete class.how did u get it as correct.can u explain it.
Can anyone futher explain to me whether iam correct or not?

Similar Messages

  • Explanation regarding a constructer

    I came accros a SCJP MCQ that is to get the out put of a simple programe.
    class A{
         public A(String s){                                                           //line X
              System.out.println("Prints A");                         //line Y
         }                                                                                          //line Z
    public class B extends A{
         public B(String s){
              System.out.println("Prints B");
         public static void main(String args[]){
              new B("C prints");
    }When i compiled the code it gives out a compilation error.I have commented the line x,y,z which will then the code will compile.Can any genius give me a explanation why code didn't compile in the first place and after comenting why did it compile.

    2.1 and 1.2.
    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Creating an instance of a class from within another class

    I am trying to create an instance of MCQ in the T class but I am getting this error:
    File: E:\JAVA PROGRAMS\assignment 1\T.java [line: 15]
    Error: cannot find symbol
    symbol : class MCQ
    location: class T
    here are the two classes:
    // class T
    import java.awt.*;
    import java.util.*;
    import java.lang.*;
    public class T{
    public T(String aT)
    pest = aT;
    public static T t_one()
    T aT = new T("Calculator");
    aT.addQ(new MCQ( " 2 + 2", "equals 4", "equals 5", "equals 0", " equals -2",
    "is a prime number", 1));
    return aT;
    private String pest;
    //class Q
    import java.awt.*;
    import java.util.*;
    import java.lang.*;
    public abstract class Q{
    Vector q = new Vector();
    public String aT;
    abstract void addQ(Q aQ);
    public class MCQ extends Q{
    String a,b,c,d,e,f,g;
    int answer;
    public MCQ (String a, String b, String c, String d, String e, int answer)
    this.a = a;
    this.b = b;
    this.c = c;
    this.d = d;
    this.e = e;
    this.answer = answer;
    void addQ(Q aQ)
    q.addElement(new T(aT));
    I tried to make reference to MCQ by doing this in class T:
    MCC qT = new MCQ() ;
    but that presents a whole other set of problems.
    please help I think I have tried everything!

    Use code tags (http://forum.java.sun.com/help.jspa?sec=formatting)
    Don't import java.lang.* . You get those automatically.
    Your MCQ class is really Q.MCQ (the way you posted, anyway).
    If Q weren't abstract, you could do:
    new Q().new MCQ(...)But, you can't create a Q without defining 'add'. You could do it anonymously, but that makes no sense. Put Q and MCQ in separate files and try again.

  • Extend abstract class & implement interface, different return type methods

    abstract class X
    public abstract String method();
    interface Y
    public void method();
    class Z extends X implements Y
      // Compiler error, If I don't implement both methods
      // If I implement only one method, compiler error is thrown for not
      // implementing another method
      // If I implement both the methods,duplicate method error is thrown by 
      //compiler
    The same problem can occur if both methods throw different checked exceptions,or if access modifiers are different..etc
    I'm preparing for SCJP, So just had this weired thought. Please let me know
    if there is a way to solve this.

    Nothing you can do about it except for changing the design.
    Kaj

  • SCJP Practice Question

    I'm working through the McGraw Hill SCJP study guide for Java 5, and I don't much care for the following question:
    (page 159)
    5. Select the two statements that best indicate a situation whit low coupling. (Choose two.)
    A. The attributes of the class are all private.
    B. The class refers to a small number of other objects.
    C. The object contains only a small number of variables.
    D. The object is referred to using an anonymous variable, not directly.
    E. The reference variable is declared for an interface type, not a class. The interface provides a small number of methods.
    F. It is unlikely that changes made to one class will require any changes in another.
    Answer:
    E and F are correct. Only having access to a small number of methods implies limited coupling. If the access is via a reference of interface type, it may be argued that there is even less opportunity for coupling as the class type itself is not visible. Stating that changes in one part of a program are unlikely to cause consequences in another part is really the essence of low coupling. There is no such thing as an anonymous variable. Referring to only a small number of other objects might imply low coupling, but if each object has many methods, and all are used, then coupling is high. Variables (attributes) in a class should usually be private, but this describes encapsulation, rather than low coupling. Of course, good encapsulation tends to reduce coupling as a consequence.
    I would have thought A and E were the answers here. If the attributes of a class are all private, you're going to have to use accessors and mutators to get to them, which is a prime example of loosely coupled code. I disagree that "F. It is unlikely that changes made to one class will require any changes in another." is a proper answer because although it does cut right to the heart of the matter, it does not describe the mechanism through which this feat has been accomplished and leads me to believe that perhaps the class has been designed with likely future changes in mind such that they will have a low impact but other unforseen changes may cause problems.
    Am I out of line here?
    If so, please enlighten me!
    If not, ... yarrrgh! If there are questions like this on the exam, I expect to have problems with them. Any suggestions? How can I get my reasoning to line up with the test, at least for the day of the exam? ;)
    Thank you in advance for any assistance!

    I think you're making a general mistake you have to come to terms with before you attempt the exam. You're reading stuff into the statements that aren't there. You must learn to consider the statements just as they stand and don't modify them in your mind.
    For example,
    If the attributes of a class are all
    private, you're going to have to use accessors and
    mutators to get to them,That's not what the statement says. It says all attributes are private, nothing else.
    it does cut right to the heart of the
    matter, it does not describe the mechanism through
    which this feat has been accomplishedWho said mechanisms must be provided? The statement cuts right to the heart of the matter as it stands.

  • Bean class not found error...

    I am using Tomcat 4.0 on windows 98, when I try to use my bean class from jsp program, I get class not found error. I read/followed all the similar problems in the forum but still have not been able to solve the problem.
    The error I get is as follows:
    ==============================
    type Exception report
    message Internal Server Error
    description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    An error occurred at line: 1 in the jsp file: /handoff1.jsp
    Generated servlet error:
    D:\Apps\Apache\Tomcat4.0\work\Standalone\localhost\cartapp\handoff1$jsp.java:56: Class com.cartapp.user.User not found.
    com.cartapp.user.User handoff = null;
    ^
    An error occurred at line: 1 in the jsp file: /handoff1.jsp
    Generated servlet error:
    D:\Apps\Apache\Tomcat4.0\work\Standalone\localhost\cartapp\handoff1$jsp.java:59: Class com.cartapp.user.User not found.
    handoff= (com.cartapp.user.User)
    ^
    An error occurred at line: 1 in the jsp file: /handoff1.jsp
    Generated servlet error:
    D:\Apps\Apache\Tomcat4.0\work\Standalone\localhost\cartapp\handoff1$jsp.java:64: Class com.cartapp.user.User not found.
    handoff = (com.cartapp.user.User) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "com.cartapp.user.User");
    ^
    3 errors, 1 warning
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:285)
    at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:548)
    =============================================
    Location of files
    ==================
    My jsp file is located at:
    D:\Apps\Apache\Tomcat4.0\webapps\ROOT\cartapp
    my bean class - User - is at:
    D:\Apps\Apache\Tomcat4.0\webapps\ROOT\WEB-INF\classes\com\cartapp\user
    Contents of the jsp file
    =======================
    <jsp:useBean id="handoff" scope="session" class="com.cartapp.user.User" />
    <HTML>
    <BODY>
    This is the setting page!
    <%
    handoff.setFirstName("George");
    %>
    </BODY>
    </HTML>
    The first 2 lines of the class are:
    ==================================
    package com.cartapp.user;
    public class User {
    Environment settings
    ====================
    JAVA_HOME=D:\Apps\java\jdk
    CATALINA_HOME=D:\Apps\Apache\Tomcat4.0
    CLASSPATH=;.;F:\ola\progmn\JAVA\pkgs;D:\Apps\Apache\Tomcat4.0\common\lib\servlet.jar
    Can anyone please help. Thanks.
    Thanks.
    Ola Oke (SCJP 1.4)

    Not certain but try putting the classes folder in your classpath:
    D:\Apps\Apache\Tomcat4.0\webapps\ROOT\WEB-INF\classes\

  • Basic java MCQ!

    I came accros a scjp quesion that is
    Which of the following are legal declerations for non nested classes and interfaces?
    A) final abstract class Test{}
    B) public static interface Test{}
    C) final public class Test{}
    D) protected abstract class Test{}
    E) protected interface Test{}
    F) abstract public class Test{}
    I think B,C,D,E,F are correct.I know that first one is wrong because final and abstract can not be used at the same time.Am i right or wrong?Can any one give me a explanation if i am wrong.

    Answer: C,F
    Also, you are correct in that A is Incorrect.
    Hi,
    Here is how I got the answer.
    NOTE: classes and interfaces refer to outside(non-nested) ones.
    A - Incorrect - Because (as you have already identified) 'final' and 'abstract' can not be used at the same time
    B - Incorrect - In interfaces, we do not talk about anything like "instances" and "classes". An Interface contains just method signatures. So, no point of having 'static' (which is used when we need to access members by not referring to a particular instance)
    C - Correct - 'public' means class is accessible to all other classes. 'final' means cannot extend the class
    D - Incorrect - 'protected' means, not accessible outside the package. This is not applicable to classes.
    E - Incorrect - Only access modifier for interfaces is 'public'
    F - Correct - No issue in having 'public' and 'abstract'.
    Regards,
    Sidath.

  • Job oportunities as a SCJP?

    I am an MIS major (a junior) who is fairly skilled as a Java programmer. I was wondering what my job opportunities would be if I were to become a certified Java Programmer while still in college. I have a year and a half left until I get my degree so I'll need a part time job in order to allow myself to study and attend class.
    So basically what I'm asking is: What do you think my chances are of landing a part-time programming job a a SCJP without a college degree?

    the first benifit of certification is that, you will be much more comfortable with java after study for certification and it could help you in job also. may be after degree,may be now.but certainly you will gain something instead of losing . yeah I've seen people getting benefits of certification. tags are always good.

  • SCJP confusing question

    Hello guys,
    Recently I came across one web-site with mock-up SCJP questions. One of the questions and especially provided answer to it really grabs my attention:
    Can one object access a private variable of another object of the same class?
    Answer: Yes.
    Private means "private to the class", NOT "private to the object". So two objects of the same class could access each other's private data.
    If it would be true it violates the encapsulation principle of OO. Can you please explain this question/answer because it is really confusing me.

    All kidding aside here - ask yourself: "Why would I want to make anything private in a class?". Then you might answer "Well, for one thing I do not want to be able to de-stabilize the class when I use it for what it is."
    An example of such use is any use of the API classes from SUN. No instantiated Object from these has access to the private members, unless though public methods - which control such access.
    But you might ask: "And why would I want to take that ability away from the class itself?" Well: "In answer you maight say that you would not want to, and continue by saying that's not what you mean."
    Well since one would need to build in that capability - the previous example used an inner class with a change method - this is not the same as allowing outside access. If you tried to do something like from another toplevel public class without any public alteration methods in the member class you couldn't do it - you'd get a "x has private access in y" type message.
    ~Bill
    .

  • Abstract Classes and Method

    Hi all,
    I want to appear for SCJP exam and studying for the same ,
    Can anyone tell whether concrete methods in an abstract class can be overridden by its subclass or not ... ???
    Thanks in advance ,
    Suvo

    Hai
    Actually the overridden concept is supported when the methods are default, protected, public with some constraints, not only when they are protected and public.
    The access specifier in the overriding method (in the derived class) should not be more limiting than that of the overriden method (in the base class). This means that if the access specifier for base class method is protected then the access specifier for the derived class method should not be default or private but can be protected, public. The order of increasing visibility of various specifiers is:
    default
    protected
    public
    Thanks,
    Hari
    Edited by: Hari on Jun 3, 2011 8:45 PM

  • Why a nested class can instantiate an abstract class?

    Hi people!
    I'm studying for a SCJP 6, and i encountered this question that i can figure it out but i don't find any official information of my guess.
    I have the following code:
    public class W7TESTOQ2 {
        public static void main(String[] args) {
           // dodo dodo1 = new dodo();
            dodo dodo2 =new dodo(){public String get(){return "filan";}};
            dodo.brain b = dodo2.new brain(){public String get(){return "stored ";}};
            System.out.print(dodo2.get()+" ");
            System.out.println(b.get());
    abstract class dodo
        public String get()
            return "poll";
        abstract class brain
            public abstract String get();
    }I know that abstract classes cannot be instantiated but i see that in this example, with a nested anonymous class it does (dodo and brain classes). My guess is that declaring the nested class it makes a subclass of the abstract class and doing so it can be instantiated. But i can't find any documentation about this.
    Does anybody know?
    Really thanks in advance.
    Regards,
    Christian Vielma

    cvielma wrote:
    Another question about this. Why can't i declare a constructor in the nested class? (it gives me return type required)You cannot declare a constructor, because in one line you're declaring a new class (the anonymous inner class) as well as constructing an instance of it.
    What you can do, however, is if the abstract class (or the superclass, in any case, it doesn't need to be abstract) defines several constructors, you can call them.
    public abstract MyClass {
        public MyClass() {
            // Default do nothing constructor
        public MyClass(String s) {
            // Another constructor
    // Elsewhere
    MyClass myclass = new MyClass("Calling the string constructor") {
    };But you can't define your own constructors in the anonymous inner class.
    Also, since the class is anonymous, what would you name the constructor? :)
    Edited by: Kayaman on 26.6.2010 22:37

  • SCJP Studying problem

    Hello all,
    I am currently studying for the SCJP, however I am finding a MAJOR problem with studying. During the reading of the chapters, I manage to understand exectly what the book explains. I also experiment and try out things, however, when I come to make the small exam that each chapter offers, I get a very low mark. I would like to know if this is a typical thing that happens to everyone or if its me. Like for example.. I know an abstract class must be marked abstract and each method which is not going to be implemented must end with a semicolon and be marked abstract.... however I still manage to get the question wrong.. I feel I know the subject but during the exam, I flip.
    Does this thing happen to any of you people? This is getting very boring and demotivating a lot!!
    Thanks.. I need some CONSTRUCTIVE arguments or anything POSITIVE please :) (if you know what I mean hehe)

    Learn to read and understand the questions as well as the material they cover.
    Low scores if you know the subject under examination is almost always a result of not reading the question properly, either by being rushed (and thus not taking your time) or by a poor understanding of the language the questions are worded in (meaning English, not Java).
    If you're also nervous (as you shouldn't be for a practice test in a book, but quite understandable during a real exam) things only get worse.

  • Confusing SCJP 6 mock exam questions

    Given:
    *class StringSplit {*
    *public static void main(String [] args) {*
    String s = "x1234 y56 z7 a";
    String [] sa = s.split("\d");
    int count = 0;
    for( String x : sa)
    count++;
    System.out.println("total: " + count);
    What is the result?
    The "correct" answer for this question on the guide I'm using is 8.
    I chose "Compilation Fails" based on my prior experience with other mock exams because some questions like these say that \d needs an extra \ (so \\d). For crying out loud, I even tested this code and it failed due to the missing escape.
    Anyway, when I run into this type of question on the SCJP, and there's something like \d or \w or \s showing up, should I assume that it's a valid delimiter or assume that it's not escaped properly?
    Thank you.
    Edited by: lapchern on Feb 1, 2010 10:31 PM
    Edited by: lapchern on Feb 1, 2010 10:34 PM

    please, edit your question and use the tag (there is a button in the editor window)                                                                                                                                                                                   

  • Tips for the (SCJP) [Fountation Java on Platform J2SE 1.5]

    Does anybody have any tips or things i should know before the i take the (SCJP) [Fountation Java on Platform J2SE 1.5]? Any stuff i should definitly know.
    Thank you.

    The java tutorials.
    Exam objectives:
    http://ca.sun.com/training/catalog/courses/CX-310-055.xml
    http://java.sun.com/docs/books/tutorial/java/index.html
    http://java.sun.com/docs/books/tutorial/essential/index.html
    Shoud get you objectives 1,2, 4, (large part of) 5 and 7
    3, 6 and some part of 5 are new to 1.5 or just API specific (Threads are delt with in the
    tutorial but section 3 mentions some other classes you should know of).
    In 1.4 you needed to know some swing but that seems to be gone now, use this tutorial
    to get to know a little swing:
    http://java.sun.com/docs/books/tutorial/uiswing/index.html
    These you should allso read:
    http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html
    http://java.sun.com/docs/books/tutorial/i18n/TOC.html
    http://java.sun.com/docs/books/tutorial/extra/regex/index.html
    http://java.sun.com/docs/books/tutorial/collections/TOC.html
    play arround with the following classes:
    BufferedReader,BufferedWriter, File, FileReader, FileWriter, PrintWriter.
    DataInputStream, DataOutputStream, FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutputStream, Serializable.
    That would get you about 90% of what you need to know, check the objectives and
    read the tutorial if any objective is not in the URL's posted above than google for it
    (note that this forum will put spaces in long URLs):
    http://www.google.com/search?hl=nl&q=site%3Asun.com+%22anotherObjective%22+tutorial&btnG=Zoeken&meta=
    For questions:
    http://www.google.nl/search?hl=nl&q=scjp+%22exam+questions%22&btnG=Zoeken&meta=
    http://www.certgear.com/products/preview/SCJP/scjp3.html

  • Errors in SCJP exam

    Hi,
    I am sitting my SCJP 1.5 exam tomorrow and just going through the Sun sample exam that I bought on-line from Sun.
    In the first exam (you get 3), question 50 states that...
    Is-a relationships must use inheritance
    However, the instanceof test will also return true for an implementation of an Interface. Am I wrong or is this a mistake in the exam papers? I searched through the forum and this doesn't seem to be the first such error, which leads me to question if the sample papers are incorrect, is there any way of knowing if there are any mistakes in the actual exam?
    Thanks!
    Alan K.
    Ps: The sample exams cost nearly twice the price from the European based website than the USA website.... not impressed!!

    At the risk of suffering the ridicule of JWenting, here are 3 other - shameful - mistakes that I noticed on the 3rd practice exam:
    Question 27 has BufferWriter 3 times instead of BufferedWriter. For all of the idiotic 'gotcha' questions that the exam throws at you - and considering that Sun charges $75 for these practice exams, this should have been caught.
    Question 29 is even worse:
    Given:
    1. class Dog implements Serializable {
    2.   Collar c = new Collar();
    3. }
    4. class Collar implements Serializable {
    5.   CollarPart cp1 = new CollarPart("handle");
    6.   CollarPart cp2 = new CollarPart("clip");
    7. }
    8.
    9. class CollarPart implements Serializable { }When an instance of Dog is serialized, how many objects are serialized?
    My thoughts: Although they claim 4 should be serialzied, the answer should be Zero, because the code won't compile. You can't serialize a Dog instance, because you can't serialize a Collar instance, because cp1 and cp2 are instantiated with a non-existent constructor.
    And, by far the worst of all is Question 58:
    1. import java.util.*;
    2. class DumpArray {
    3.   public static void main(String [] args) {
    4.     int [] a = {7,9,8};
    5.     int [][] aa = {{1,2,3}, {6,5,4}};
    6.     int [][][] aaa = {{{1,2}, {3,4}}, {{5,6},{7,8}}};
    7.
    8.     System.out.println(Arrays.deepToString(a));
    9.     System.out.println(Arrays.deepToString(aa));
    10.     System.out.println(Arrays.deepToString(aaa));
    11.   }
    12. }Which invocation (or invocations) of deepToString will compile?
    My thoughts: The answer claims that only lines 9 and 10 will compile b/c deepToString can be used only with multidimensional arrays. Wrong!!! There's no way to sugarcoat it- that is just totally wrong.
    So, does the real test have problems like this? I'm annoyed.

Maybe you are looking for