SlideShare a Scribd company logo
1 of 4
QUESTION1

    What is the result of attempting to compile and run this
         interface A{
          void aMethod();
          }
          public class Test implements A{
          void aMethod(){
          System.out.println("hello");
          }
          public static void main(String[] args){
          Test t = new Test();
          t.aMethod();
          }
         }

1. The code will not compile.
2. Runtime exception.
3. Compiles and runs printing out "hello".

ANS : 1

     All interface methods are implicitly public.
     Will fail compilation becuse the access modifier
     for aMethod() is being made more restrictive.

QUESTION2

     Is this code legal ?
         public class Test {
          void aMethod(){
          static int b = 10;
          System.out.println(b);
          }
         }

1. Yes
2. No

ANS : 2
   Local variables cannot be declared static.

QUESTION3
    Is this legal
          public class Test {
            static { int a = 5; }
            public static void main(String[] args){
            System.out.println(a);
            }
          }

1.Yes
2.No

ANS : 2
  Correct ans : 2
  A variable declared   in a static initialiser is not accessible outside its
  enclosing block.
QUESTION4

      Select the true statements.

1.   Transient methods cannot be overridden
2.   A final class may not be subclassed.
3.   A private method can never be overridden to become public
4.   An abstract class may contain final methods
5.   A private method cannot be overridden and made public
6.   Final methods may not be overridden.

ANS : 2,4,5,6

QUESTION5

       Which of the following are valid for declaring and intialising
       a char variable?

1.   char   c       =   'a';
2.   char   c       =   ''';
3.   char   c       =   'n';
4.   char   c       =   "a";
5.   char   c       =   u0061;
6    char   c       =   97;

ANS : 1

     Corr answer : 1,2,3 and         6

QUESTION6

      Which of the following are valid for declaring and initialising
      a boolean variable?

1.   boolean    b   =   True;
2.   boolean    b   =   0;
3.   boolean    b   =   1 < 2;
4.   boolean    b   =   true?false:true;
5.   boolean    b   =   true;

ANS : 3,4,5

QUESTION7

        Select the valid declarations.

1.   int i = 16.0;
2.   byte b = 16.0;
3.   float f = 16.0;
4.   double d = 16.0;
5.   char u0063 = 'u0063';

ANS : 4,5
     16.0 is a double type literal hence it becomes a widening
     assignment for a byte, int or float.

QUESTION8
What is the result of attempting to compile and run this code
       public class Test{
         int i;
         Test(){
         i++;
         }
         public static void main(String[] args){
         Test t = new Test();
         System.out.println("value = " t.i);
         }
       }

1.   The   code   will compile and run printing out value = 1
2.   The   code   will compile and run printing out value = 0
3.   The   code   will fail to compile becuse i has not been initialised
4.   Run   time   error

ANS : 1
   Numeric instance variables are always
   automatically initialised to its default value.
   So you can use them without explicitly initialising them.

QUESTION9

      Whhat is the result of attempting to compile and run the following
        public class Test{
           int arr[] = new int[8];
           public static void main(String[] args){
            Test t = new Test();
           System.out.println(t.arr[7]);
            }
        }

1. Compiler error
2. Runtime exception
3. Compiles and runs printing out 0

ANS : 3

     Numeric instance variables are always
     automatically initialised to its default value.
     In the case of arrays each element of the array is
     initialised to its defaut value.

QUESTION10

     What is the result of trying to compile and run this
             public class Test{
                 public static void main(String[] args){
             int a;
                    Test t = new Test();
                    for(int j=0; j < 2 ; j++){
                        for(int i=0; i <4 ; i++){
                         a = j;
                         }
                    System.out.println(i);
                    }
}
           }

1.   Compiles without error and runs printing out 1 twice.
2.   Compiles without error and runs printing out 0 followed by 1 .
3.   Compiles without error and runs printing out 0 twice.
4.   Runtime error
5.   Does not compile

ANS : 5

     The variable i is not accessible outside the enclosing block of the
     inner loop.

More Related Content

What's hot

Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
Conditions In C# C-Sharp
Conditions In C# C-SharpConditions In C# C-Sharp
Conditions In C# C-SharpAbid Kohistani
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetitionOnline
 
Chapter 5:Understanding Variable Scope and Class Construction
Chapter 5:Understanding Variable Scope and Class ConstructionChapter 5:Understanding Variable Scope and Class Construction
Chapter 5:Understanding Variable Scope and Class ConstructionIt Academy
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statementsKuppusamy P
 
Jumping statements
Jumping statementsJumping statements
Jumping statementsSuneel Dogra
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision ControlJayfee Ramos
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersSushant Choudhary
 
Symbolic Execution (introduction and hands-on)
Symbolic Execution (introduction and hands-on)Symbolic Execution (introduction and hands-on)
Symbolic Execution (introduction and hands-on)Emilio Coppa
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statementsrajshreemuthiah
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareGagan Deep
 
Control statements in java
Control statements in javaControl statements in java
Control statements in javaManojkumar C
 

What's hot (20)

Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
Conditions In C# C-Sharp
Conditions In C# C-SharpConditions In C# C-Sharp
Conditions In C# C-Sharp
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetition
 
Chapter 5:Understanding Variable Scope and Class Construction
Chapter 5:Understanding Variable Scope and Class ConstructionChapter 5:Understanding Variable Scope and Class Construction
Chapter 5:Understanding Variable Scope and Class Construction
 
07 flow control
07   flow control07   flow control
07 flow control
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
White box testing
White box testingWhite box testing
White box testing
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
 
Symbolic Execution (introduction and hands-on)
Symbolic Execution (introduction and hands-on)Symbolic Execution (introduction and hands-on)
Symbolic Execution (introduction and hands-on)
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 

Similar to Scjp questions

Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentalsKapish Joshi
 
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdfAll based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdfaroraenterprisesmbd
 
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Udayan Khattry
 
Question 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docxQuestion 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docxamrit47
 
Software testing lab manual
Software testing lab manualSoftware testing lab manual
Software testing lab manualTanzeem Syed
 
Test final jav_aaa
Test final jav_aaaTest final jav_aaa
Test final jav_aaaBagusBudi11
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSESujata Regoti
 
1 Midterm Preview Time allotted 50 minutes CS 11.docx
1  Midterm Preview Time allotted 50 minutes CS 11.docx1  Midterm Preview Time allotted 50 minutes CS 11.docx
1 Midterm Preview Time allotted 50 minutes CS 11.docxhoney725342
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfShashikantSathe3
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style GuideJacky Lai
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfSHASHIKANT346021
 
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdf
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdfAll based on Zybooks = AP Java with zylabsPlease answer all questi.pdf
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdfdeepakarora871
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IAbdul Rahman Sherzad
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paperfntsofttech
 

Similar to Scjp questions (20)

Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentals
 
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdfAll based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdf
 
Core java
Core javaCore java
Core java
 
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
 
Nalinee java
Nalinee javaNalinee java
Nalinee java
 
Java Quiz
Java QuizJava Quiz
Java Quiz
 
7
77
7
 
Question 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docxQuestion 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docx
 
Software testing lab manual
Software testing lab manualSoftware testing lab manual
Software testing lab manual
 
UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
 
Test final jav_aaa
Test final jav_aaaTest final jav_aaa
Test final jav_aaa
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSE
 
1 Midterm Preview Time allotted 50 minutes CS 11.docx
1  Midterm Preview Time allotted 50 minutes CS 11.docx1  Midterm Preview Time allotted 50 minutes CS 11.docx
1 Midterm Preview Time allotted 50 minutes CS 11.docx
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdf
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style Guide
 
LECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdfLECTURE 3 LOOPS, ARRAYS.pdf
LECTURE 3 LOOPS, ARRAYS.pdf
 
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdf
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdfAll based on Zybooks = AP Java with zylabsPlease answer all questi.pdf
All based on Zybooks = AP Java with zylabsPlease answer all questi.pdf
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART I
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 

Recently uploaded

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Recently uploaded (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Scjp questions

  • 1. QUESTION1 What is the result of attempting to compile and run this interface A{ void aMethod(); } public class Test implements A{ void aMethod(){ System.out.println("hello"); } public static void main(String[] args){ Test t = new Test(); t.aMethod(); } } 1. The code will not compile. 2. Runtime exception. 3. Compiles and runs printing out "hello". ANS : 1 All interface methods are implicitly public. Will fail compilation becuse the access modifier for aMethod() is being made more restrictive. QUESTION2 Is this code legal ? public class Test { void aMethod(){ static int b = 10; System.out.println(b); } } 1. Yes 2. No ANS : 2 Local variables cannot be declared static. QUESTION3 Is this legal public class Test { static { int a = 5; } public static void main(String[] args){ System.out.println(a); } } 1.Yes 2.No ANS : 2 Correct ans : 2 A variable declared in a static initialiser is not accessible outside its enclosing block.
  • 2. QUESTION4 Select the true statements. 1. Transient methods cannot be overridden 2. A final class may not be subclassed. 3. A private method can never be overridden to become public 4. An abstract class may contain final methods 5. A private method cannot be overridden and made public 6. Final methods may not be overridden. ANS : 2,4,5,6 QUESTION5 Which of the following are valid for declaring and intialising a char variable? 1. char c = 'a'; 2. char c = '''; 3. char c = 'n'; 4. char c = "a"; 5. char c = u0061; 6 char c = 97; ANS : 1 Corr answer : 1,2,3 and 6 QUESTION6 Which of the following are valid for declaring and initialising a boolean variable? 1. boolean b = True; 2. boolean b = 0; 3. boolean b = 1 < 2; 4. boolean b = true?false:true; 5. boolean b = true; ANS : 3,4,5 QUESTION7 Select the valid declarations. 1. int i = 16.0; 2. byte b = 16.0; 3. float f = 16.0; 4. double d = 16.0; 5. char u0063 = 'u0063'; ANS : 4,5 16.0 is a double type literal hence it becomes a widening assignment for a byte, int or float. QUESTION8
  • 3. What is the result of attempting to compile and run this code public class Test{ int i; Test(){ i++; } public static void main(String[] args){ Test t = new Test(); System.out.println("value = " t.i); } } 1. The code will compile and run printing out value = 1 2. The code will compile and run printing out value = 0 3. The code will fail to compile becuse i has not been initialised 4. Run time error ANS : 1 Numeric instance variables are always automatically initialised to its default value. So you can use them without explicitly initialising them. QUESTION9 Whhat is the result of attempting to compile and run the following public class Test{ int arr[] = new int[8]; public static void main(String[] args){ Test t = new Test(); System.out.println(t.arr[7]); } } 1. Compiler error 2. Runtime exception 3. Compiles and runs printing out 0 ANS : 3 Numeric instance variables are always automatically initialised to its default value. In the case of arrays each element of the array is initialised to its defaut value. QUESTION10 What is the result of trying to compile and run this public class Test{ public static void main(String[] args){ int a; Test t = new Test(); for(int j=0; j < 2 ; j++){ for(int i=0; i <4 ; i++){ a = j; } System.out.println(i); }
  • 4. } } 1. Compiles without error and runs printing out 1 twice. 2. Compiles without error and runs printing out 0 followed by 1 . 3. Compiles without error and runs printing out 0 twice. 4. Runtime error 5. Does not compile ANS : 5 The variable i is not accessible outside the enclosing block of the inner loop.