Mobile Application Development ( IT 100 ) Assignment - I
|
|
- Jeffery Chandler
- 6 years ago
- Views:
Transcription
1 1. a) Explain various control structures available in Java. (6M ) Various control structures available in Java language are: 1. if else 2. switch 3. while 4. do while 5. for 6. break 7. continue 8. return 1. if else statement: This statement helps to select one out of two possibilities based on the given conditions. This statement is also called conditional branch statement. General form of the if statement is : if(condition) statement1; else statement2; here each statement may be a single statement or compound statement enclosed in a curly braces. The condition is any expression that returns a boolean value. The else clause is optional. If the condition is true, then statement1 is executed. Otherwise, statement2 ( if exists ) is executed. Ex: int a=10, b=20; if(a<b) System.out.println( a is smaller ); else System.out.println( b is smaller ); nested if else statement : Nested if else statement is made by placing one if-else in another if-else statement. Nested if-else statement helps to select one out of many choices. The general form of the nested if-else statement is: if(condition1) if(condition2) if(condition3) statement4 else statement3 else statement2 else statement1 In the nested if-else statement, the outermost if is evaluated first. If the condition1 tested is false, the statement1 in the outermost else is evaluated and if-else ends. If the condition1 results in true, the control goes to execute the next inner if statement. If condition2 is false, statement2 is executed. Otherwise, condition3 is evaluated. If condition3 is false, statement3 is executed, otherwise statement4 is executed. 2. switch statement: The switch statement is Java s multi way branching statement. It helps to select one out of many choices. The general form of switch statement is: switch(expression) case val1: statement1; break; case val2: statement2; break; case val3: statement3; break;... case valn: statement; break; 3. while statement: The while statement is used for looping or iterating a block of statements while the given condition is true. Department of Information Technology, BEC, Bapatla Page 1
2 The general form of the while statement is : While(condition) statements; The condition, when evaluated, must result in the boolean value true or false. As long as the condition gives true, the statement block will be executed. When the condition becomes false, the control leaves the block statement. Ex : int n=10; while(n>0) System.out.println(n); n--; 4. do while statement: The do while control statement is used for looping a block of statements while the given condition is true. In this structure, the condition is tested at the end of the block. This is in contrast to the while statement, where the condition is tested at the start of the block. The general form of the do while statement is: do statements; while(condition); The condition tested can be any expression that will yield a boolean value. As long as the condition tested is true, the whole block will be executed. Once the condition tested becomes false, the control leaves the block. It is to be noted that the block is executed once before the condition is tested. Therefore, even if the condition tested is false at the first instance itself, the block statements are executed once. Ex: int n=10; int sum=0; do sum+=n--; while(n>0); System.out.println( sum of numbers from 1 to 10 is : +sum); 5. for statement : The general form of the for loop is : for(initialization;condition;iteration) //body The for loop operates as follows. When the loop first starts, the initialization portion of the loop is executed. Next, condition is evaluated. This must be a boolean expression. This tests the loop control variable against a target value. If this expression is true, then the body of the loop is executed. If it is false, the loop terminates. Next, the iteration portion of the loop is executed. Iteration portion increments or decrements the loop control variable. The loop then iterates, first evaluating the conditional expression, then executing the body of the loop, and then executing the iteration expression with each pass. This process repeates until the controlling expression is false. Ex: for(int i=1; i<=10; i++) System.out.println(i); 6. break statement : break statement is used in for, while and do..while statements to exit the loop. It is also used in switch statement to terminate the statement sequence. Ex: i=0; while(i<10) if(i==5) break; else System.out.print(i+ );i++; 7. continue statement: The continue statement is used inside control blocks. When the continue statement is executed, the control skips the remaining portion of the loop and goes to the beginning of the loop and continue. Ex: int i=0; While(i<10) If(i%2==0) continue; System.out.println(i); i++; Department of Information Technology, BEC, Bapatla Page 2
3 8. return statement : The return statement is used to explicitly return from a method. That is, it causes program control to transfer back to the caller of the method. void m() int i=10; if(i>5) return; else System.out.println(i); 1(b). Explain various access specifiers available in Java. ( 4M ) Using Encapsulation, you can control what parts of a program can access the members of a class. By controlling access, you can prevent misuse. How a member of a class can be accessed is determined by the access specifier that modifies its declaration. Java supports the 4 types of access specifiers: 1. public 2. private 3. protected 4. no access specifier ( default ) When a member of a class is specified as public, that member can be accessed by any other code. When a member of a class is specified as private, that member can only be accessed by other members of its class. When a member of a class is declared as protected, then that member is accessible in the whole package ( package is a collection of classes ) and in the subclass of another package. When a member of a class is declared without any access specifier, then that member is accessible in the whole package only. In other packages it is not accessible. 2(a). Explain about Nested and Inner classes in Java. ( 4M ) A class defined within another class is known as nested class. A nested class has access to the members, including private members, of the class in which it is nested. However, the enclosing class does not have access to the members of the nested class. A nested class that is declared directly within its enclosing class scope is a member of its enclosing class. There are two types of nested classes: static and non-static. A static nested class is one that has the static modifier applied. An inner class is a non-static nested class. A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private. // Demonstrate an inner class. class Outer int outer_x = 100; void test() Inner inner = new Inner(); inner.display(); // this is an inner class class Inner void display() System.out.println("display: outer_x = " + outer_x); Department of Information Technology, BEC, Bapatla Page 3
4 class InnerClassDemo public static void main(string args[]) Outer outer = new Outer(); outer.test(); o/p: display: outer_x = 100 In the program, an inner class named Inner is defined within the scope of class Outer. Therefore, any code in class Inner can directly access the variable outer_x. An instance method named display( ) is defined inside Inner. This method displays outer_x on the standard output stream. The main( ) method of InnerClassDemo creates an instance of class Outer and invokes its test( ) method. That method creates an instance of class Inner and the display( ) method is called. 2(b). Explain the buzzwords of Java programming language. ( 6M ) The following are the list of Java buzzwords. Simple Secure Portable Object-oriented Robust Multithreaded Architecture-neutral Interpreted High performance Distributed Dynamic Simple: Because Java inherits the C/C++ syntax and many of the object oriented features of C++, it is easy to learn and use the Java Programming Language. The syntax for Java is, indeed, a cleaned-up version of the syntax for C++. There is no need for header files, pointer arithmetic (or even a pointer syntax), structures, unions, operator overloading, virtual base classes, and so on. If you know C++, you will find the transition to the Java syntax easy. Secure: Java is intended to be used in networked/distributed environments. Toward that end, a lot of emphasis has been placed on security. Java enables the construction of virus-free, tamper-free systems. Java s security feature allows Java program from doing overrunning the runtime stack, corrupting memory outside its own process space. Java has digitally signed classes. With a signed class, you can be sure of who wrote it. Any time you trust the author of the class, the class can be allowed more privileges on your machine. Object Oriented: object-oriented design is a technique for programming that focuses on the data (= objects) and on the interfaces to that object. To make an analogy with carpentry, an object-oriented carpenter would be mostly concerned with the chair he was building, and secondarily with the tools used to make it; a non-object-oriented carpenter would think primarily of his tools. The object-oriented facilities of Java are essentially those of C++.Java language is Object Oriented language. The Object model of Java is simple and easy to extend. Robust: Java programs are more robust means that programs run without crashes. Java provides automatic memory management and mechanism for handling of exceptional conditions (runtime errors). In a Java program all runtime errors can and should be managed by your program. Java force you to find mistakes early in program development. As Java is strictly typed language, it checks your code at both at compile time and runtime for type safety. Multithreaded: Java allows you to create and run multiple threads in a program at a time. This allows you to write programs that do many things simultaneously. Architecture-neutral: The compiler generates an architecture-neutral object file format the compiled code is executable on many processors, given the presence of the Java run time system. The Java compiler Department of Information Technology, BEC, Bapatla Page 4
5 does this by generating bytecode instructions which have nothing to do with a particular computer architecture. Rather, they are designed to be both easy to interpret on any machine and easily translated into native machine code on the fly. Interpreted: The Java interpreter can execute Java byte codes directly on any machine to which the interpreter has been ported. High Performance: Java byte code was designed so that it easy to translate into native machine (machine code for the particular CPU the application is running on) code for very high performance by using JIT ( Just In-Time ) compiler. Distributed: Java is designed for developing applications in distributed environment using Java RMI ( Remote Method Invocation ). Dynamic: Java programs carry with them substantial amounts of run-time type information that is used to verify and resolve accesses to objects at run time. This makes it possible to dynamically link code in a safe and easy manner. 3 a) Define an interface and write a program for implementing multiple inheritance. (5M) Interface: Using the keyword interface, you can fully abstract a class interface from its implementation. That is, using interface, you can specify what a class must do, but not how it does it. Interfaces are syntactically similar to classes, but they lack instance variables, and their methods are declared without any body. the general form of an interface: access interface name return-type method-name1(parameter-list); return-type method-name2(parameter-list); type final-varname1 = value; type final-varname2 = value; //... return-type method-namen(parameter-list); type final-varnamen = value; Here, access is either public or not used. name is the name of the interface. Interfaces help to realize the functionality of multiple inheritance in Java. Program for implementing multiple inheritance: // multiple inheritance (MultipleInherit.java) interface Exam void percent_cal(); class Student String name; int roll_no,mark1,mark2; Student(String n, int r, int m1, int m2) name=n; roll_no=r; mark1=m1; mark2=m2; void display() Department of Information Technology, BEC, Bapatla Page 5
6 System.out.println ("Name of Student: "+name); System.out.println ("Roll No. of Student: "+roll_no); System.out.println ("Marks of Subject 1: "+mark1); System.out.println ("Marks of Subject 2: "+mark2); class Result extends Student implements Exam Result(String n, int r, int m1, int m2) super(n,r,m1,m2); public void percent_cal() int total=(mark1+mark2); float percent=total*100/200; System.out.println ("Percentage: "+percent+"%"); void display() super.display(); class MultipleInherit public static void main(string args[]) Result R = new Result("Ravi",12,93,84); R.display(); R.percent_cal(); o/p: Name of Student: Ravi Roll No. of Student: 12 Marks of Subject 1: 93 Marks of Subject 2: 84 Percentage: 88.0% 3. b) Explain about super keyword with an example program in Java. (5M) Whenever a subclass needs to refer to its immediate super class, it can access super class members by using super keyword. super keyword is used for two purposes. 1. To call the super class constructor 2. To access a member of a super class that has been hidden by a member of a subclass. 1. super( ) To call super class constructor : A subclass can call a constructor method defined by its superclass by use of the following form of super: super(parameter-list); Here, parameter-list specifies any parameters needed by the constructor in the superclass. super() must always be the first statement executed inside a subclass constructor. 2. second use of super keyword: super keyword is used to access the members of a superclass hidden by sub class members in the subclass. form: super.member Department of Information Technology, BEC, Bapatla Page 6
7 Here, member can be a method or an instance variable. Example Program: //usage of super keyword class Vehicle int speed=50; Vehicle() System.out.println("Vehicle is created"); class Bike extends Vehicle int speed=100; Bike() super(); System.out.println("Bike is created"); void display() System.out.println(super.speed); public static void main(string args[]) Bike b=new Bike(); b.display(); o/p: Vehicle is created Bike is created a) Explain method overriding with an example program. (5M) A method in a subclass has the same name, type of the variables and order of the variables as a method in its super class, then the method in the subclass is said to be override the method in the super class. The process is called Method Overriding. In such process the method defined by the super class will be hidden. When the method is called, the method defined in the super class has invoked and executed instead of the method in the super class. The super reference followed by the dot (.) operator may be used to access the original super class version of that method from the subclass. Note 1: Method Overriding occurs only when the name and type signature of the two methods are identical. Note 2: If method name is identical and the type signature is different, then the process is said to be Method Overloading. Example Program: class A int i,j; public A(int a,int b) i=a; j=b; void show() System.out.println("i="+i+"\n"+"j="+j); Department of Information Technology, BEC, Bapatla Page 7
8 class B extends A int k; B(int a,int b,int c) super(a,b); k=c; void show() System.out.println("k="+k); class override public static void main(string[] args) B obj=new B(1,2,3); obj.show(); o/p: k=3 4. b) Explain the abstract class with an example program. (5M) Classes from which objects cannot be instantiated with new operator are called Abstract Classes. Each abstract class contains one or more abstract methods. In a class if there exist any method with no method body is known as abstract method. An abstract method is declared as syntax: abstract type method-name (parameter-list); abstract is a keyword used for declaring abstract methods. To declare a class as abstract, use the abstract keyword in front of the class keyword at the beginning of the class declaration. No objects are created to an abstract class. For the abstract methods, the implementation code will be defined in its subclass. Example Program: abstract class figure double dim1,dim2; figure(double x,double y) dim1=x; dim2=y; abstract double area(); class rectangle extends figure rectangle(double a,double b) super(a,b); double area() System.out.println("Rectangle Area"); return dim1*dim2; Department of Information Technology, BEC, Bapatla Page 8
9 class triangle extends figure triangle(double x,double y) super(x,y); double area() System.out.println("Triangle Area"); return dim1*dim2/2; class abs public static void main(string[] args) //figure obj=new figure(10,10); //error rectangle obj1=new rectangle(9,5); System.out.println("Area="+obj1.area()); triangle obj2=new triangle(10,8); figure a; a=obj2; System.out.println("Area="+a.area()); o/p: Rectangle Area Area=45.0 Triangle Area Area=40.0 Note: We cannot declare any abstract constructors. Concrete (general) methods are also being inside any abstract class. Abstract classes are used for general purposes. An abstract class must be subclass and override it methods. Super class has only method name and signature end with semicolon. Abstract classes cannot be used to instantiate objects, but they can used to create object reference due to Java supports Run-time Polymorphism. 5. a) Explain about static keyword in Java. (5M) Generally each class contains instance variables and instance methods. Every time the class is instantiated, a new copy of each of them is created. They are accessed using the objects with the dot operator. If we define a member that is common to all the objects and accessed without using a particular object i.e., the member belong to the class as a whole rather than the objects created from the class. Such facility can be possible by using static keyword. The members declared with the static keyword are called static members. Example: static int x; static int show(int x,int y); Department of Information Technology, BEC, Bapatla Page 9
10 The important points about static class members are Static members can be accessible without the help of objects. It can be accessible by using the syntax: classname.members; A static method can access only static members (data + method) A static block will be executed first (before main). Static variables are initialized first A static member data store the same memory for all objects Static method cannot be referred to this or super in anyway. Example 1: class static1 static int c=0; void increment() c++; void display() System.out.println("Value="+c); class Mstatic public static void main(string[] args) static1 s=new static1(); static1 s1=new static1(); static1 s2=new static1(); s.increment(); s1.increment(); s2.increment(); s.display(); s1.display(); s2.display(); o/p: value=3 value=3 value=3 without static keyword s1 s2 s3 with static keyword 0 s1 s2 s3 Example 2: class static1 static int a=10; static int b=34; static void call() Department of Information Technology, BEC, Bapatla Page 10
11 System.out.println("Value1="+a); class Mstatic1 public static void main(string[] args) static1.call(); System.out.println("Value2="+static1.b); o/p: Example 3: Value1=10 Value2=34 class static2 static int a=10,b; static void method(int x) System.out.println("x="+x); System.out.println("a="+a); System.out.println("b="+b); static System.out.println("static block"); b=a*4; class Mstatic2 public static void main(string[] args) static2.method(35); o/p: static block x=35 a=10 b=40 5. b) What is runtime polymorphism. Write a program for implementing it. (5M) Method Overriding forms on the basis of Java concept Dynamic Method Dispatch. It is the mechanism by which a call to an overridden function is resolved at run time, rather than compile time. And this method is very useful to show for Java implements run-time polymorphism. Super class reference variable can refer to a subclass object is the principle to resolve calls to overridden methods at run time. If a super class contains a method that is overridden by a subclass, then when different types of objects are referred to through a super class reference variable, different version of the methods are executed and the determination is made at run time. // run-time polymorphism example program class Figure double dim1; double dim2; Department of Information Technology, BEC, Bapatla Page 11
12 Figure(double a, double b) dim1 = a; dim2 = b; double area() System.out.println("Area for Figure is undefined."); return 0; class Rectangle extends Figure Rectangle(double a, double b) super(a, b); // override area for rectangle double area() System.out.println("Inside Area for Rectangle."); return dim1 * dim2; class Triangle extends Figure Triangle(double a, double b) super(a, b); // override area for right triangle double area() System.out.println("Inside Area for Triangle."); return dim1 * dim2 / 2; class FindAreas public static void main(string args[]) Figure f = new Figure(10, 10); Rectangle r = new Rectangle(9, 5); Triangle t = new Triangle(10, 8); Figure figref; figref = r; System.out.println("Area is " + figref.area()); figref = t; System.out.println("Area is " + figref.area()); figref = f; System.out.println("Area is " + figref.area()); o/p: Inside Area for Rectangle. Area is 45.0 Inside Area for Triangle. Area is 40.0 Area for Figure is undefined. Area is a) Explain the final keyword with an example program. (5M) A final is a keyword used for three purposes. They are Department of Information Technology, BEC, Bapatla Page 12
13 a) final as constant: A variable can be declared as constant with the keyword final. It must be initialized while declaring. One we initialized the variable with final keyword it cannot be modified in the program. This is similar to the const in C/C++. Example: final int x = 10; x = 45 //error b) final to prevent overriding: A method that is declared as final cannot be overridden in a subclass method. It the methods that are declared as private are implicitly final. Example: class A final void show( ) System.out.println( Hello ); class B extends A void show( ) //error System.out.println( Hai ); c) final to prevent inheritance: The class that is declared as final implicitly declares all of its methods as final. The class cannot be extended to its subclass. Example: final class A void show( ) System.out.println( Hello ); class B extends A //error void show( ) System.out.println( Hai ); 6. b) Write about Interfaces. (5M) Interface is a collection of method declaration and constants that one or more classes of objects will use. Interface definition is same as class except that it consists of the methods that are declared have no method body. They end with a semicolon after the parameter list. Syntax for an interface is as follows. Syntax: <access specifier> interface <it-name> type varname1=value; type varname2=value;.. returntype method-name1(parameter-list); returntype method-name2(parameter-list);. Here, access specifier is public or not used. public access specifier indicates that the interface can be used by any class. Otherwise, the interface will accessible to class that are defined in the same package as in the interface. interface keyword is used to declare the class as an interface. it-name is the name of the interface and it is a valid identifier. Department of Information Technology, BEC, Bapatla Page 13
14 Variables declared inside the interface are implicitly final and static. They cannot be changed in the implementing class. All the methods in an interface are implicitly abstract methods. Method implementation is given in later stages. The main difference between a class and interface is class contains methods with method body and the interface contains only abstract methods. Example: public interface shape int radius=2; public void area(int a); Implementing Interfaces: Once an interface has been defined, one or more classes can implement that interface. implements keyword used for implementing the classes. The syntax of implements is as follows. Syntax: class class-name implements interface1, interface2,.. interfacen.. // class body.. If a class implements more than one interface, the interfaces are separated with a comma operator. The methods that implement an interface must be declared public. Also type signature of the implementing method must match exactly the type signature specified in the interface definition. Interface methods are similar to the abstract classes so, that it cannot be instantiated. Interface methods can also be accessed by the interface reference variable refer to the object of subclass. The method will be resolved at run time. This process is similar to the super class reference to access a subclass object. Example: interface it1 int x=10,y=20; public void add(int a,int b); public void sub(int a,int b); class it2 implements it1 public void add(int s,int w) System.out.println("Addition="+(s+w)); public void sub(int s,int w) System.out.println("Subtraction="+(s-w)); public static void main(string[] args) it2 obj=new it2(); it1 ref; ref=obj; System.out.println(ref.x+ref.y); o/p: Addition=7 Subtraction=3 30 Department of Information Technology, BEC, Bapatla Page 14
Unit 3 INFORMATION HIDING & REUSABILITY. -Inheritance basics -Using super -Method Overriding -Constructor call -Dynamic method
Unit 3 INFORMATION HIDING & REUSABILITY -Inheritance basics -Using super -Method Overriding -Constructor call -Dynamic method Inheritance Inheritance is one of the cornerstones of objectoriented programming
More informationAnswer1. Features of Java
Govt Engineering College Ajmer, Rajasthan Mid Term I (2017-18) Subject: PJ Class: 6 th Sem(IT) M.M:10 Time: 1 hr Q1) Explain the features of java and how java is different from C++. [2] Q2) Explain operators
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationPrasanth Kumar K(Head-Dept of Computers)
B.Sc (Computer Science) Object Oriented Programming with Java and Data Structures Unit-II 1 1. Define operator. Explain the various operators in Java. (Mar 2010) (Oct 2011) Java supports a rich set of
More informationDeclarations and Access Control SCJP tips
Declarations and Access Control www.techfaq360.com SCJP tips Write code that declares, constructs, and initializes arrays of any base type using any of the permitted forms both for declaration and for
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationMethod Overriding in Java
Method Overriding in Java Whenever same method name is existing in both base class and derived class with same types of parameters or same order of parameters is known as method Overriding. Method must
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More informationSri Vidya College of Engineering & Technology
UNIT I INTRODUCTION TO OOP AND FUNDAMENTALS OF JAVA 1. Define OOP. Part A Object-Oriented Programming (OOP) is a methodology or paradigm to design a program using classes and objects. It simplifies the
More informationHierarchical abstractions & Concept of Inheritance:
UNIT-II Inheritance Inheritance hierarchies- super and subclasses- member access rules- super keyword- preventing inheritance: final classes and methods- the object class and its methods Polymorphism dynamic
More information5/23/2015. Core Java Syllabus. VikRam ShaRma
5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5
More informationOutline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors
Outline Overview history and advantage how to: program, compile and execute 8 data types 3 types of errors Control statements Selection and repetition statements Classes and methods methods... 2 Oak A
More informationPROGRAMMING LANGUAGE 2
31/10/2013 Ebtsam Abd elhakam 1 PROGRAMMING LANGUAGE 2 Java lecture (7) Inheritance 31/10/2013 Ebtsam Abd elhakam 2 Inheritance Inheritance is one of the cornerstones of object-oriented programming. It
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationJava Primer 1: Types, Classes and Operators
Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,
More informationComputer Programming, I. Laboratory Manual. Final Exam Solution
Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Final Exam Solution
More informationQuestions Answer Key Questions Answer Key Questions Answer Key
Benha University Term: 2 nd (2013/2014) Class: 2 nd Year Students Subject: Object Oriented Programming Faculty of Computers & Informatics Date: 26/4/2014 Time: 1 hours Exam: Mid-Term (C) Name:. Status:
More informationPractice for Chapter 11
Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write
More informationJava Fundamentals (II)
Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationComputer Science II (20073) Week 1: Review and Inheritance
Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system
More informationThe Java language has a wide variety of modifiers, including the following:
PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access
More informationInheritance. Transitivity
Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated
More informationSTRUCTURING OF PROGRAM
Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the
More information15CS45 : OBJECT ORIENTED CONCEPTS
15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?
More informationCREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed
CREATED BY: Muhammad Bilal Arslan Ahmad Shaad JAVA Chapter No 5 Instructor: Muhammad Naveed Muhammad Bilal Arslan Ahmad Shaad Chapter No 5 Object Oriented Programming Q: Explain subclass and inheritance?
More informationContents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix
PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring
More informationChapter 6 Introduction to Defining Classes
Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of
More informationLoops. CSE 114, Computer Science 1 Stony Brook University
Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?
More informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More informationQuestions Answer Key Questions Answer Key Questions Answer Key
Benha University Term: 2 nd (2013/2014) Class: 2 nd Year Students Subject: Object Oriented Programming Faculty of Computers & Informatics Date: 26/4/2014 Time: 1 hours Exam: Mid-Term (B) Name:. Status:
More informationQuestions Answer Key Questions Answer Key Questions Answer Key
Benha University Term: 2 nd (2013/2014) Class: 2 nd Year Students Subject: Object Oriented Programming Faculty of Computers & Informatics Date: 26/4/2014 Time: 1 hours Exam: Mid-Term (A) Name:. Status:
More informationUnit 4 - Inheritance, Packages & Interfaces
Inheritance Inheritance is the process, by which class can acquire the properties and methods of its parent class. The mechanism of deriving a new child class from an old parent class is called inheritance.
More informationData type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:
Unit IV Pointers and Polymorphism in C++ Concepts of Pointer: A pointer is a variable that holds a memory address of another variable where a value lives. A pointer is declared using the * operator before
More informationInheritance, and Polymorphism.
Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to
More informationThe Notion of a Class and Some Other Key Ideas (contd.) Questions:
The Notion of a Class and Some Other Key Ideas (contd.) Questions: 1 1. WHO IS BIGGER? MR. BIGGER OR MR. BIGGER S LITTLE BABY? Which is bigger? A class or a class s little baby (meaning its subclass)?
More informationClass, Variable, Constructor, Object, Method Questions
Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx
More informationJava: introduction to object-oriented features
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer
More informationJava Overview An introduction to the Java Programming Language
Java Overview An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationWhat are the characteristics of Object Oriented programming language?
What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is
More informationIslamic University of Gaza Faculty of Engineering Computer Engineering Department
Student Mark Islamic University of Gaza Faculty of Engineering Computer Engineering Department Question # 1 / 18 Question # / 1 Total ( 0 ) Student Information ID Name Answer keys Sector A B C D E A B
More informationInheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes
Inheritance Inheritance is the mechanism of deriving new class from old one, old class is knows as superclass and new class is known as subclass. The subclass inherits all of its instances variables and
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationObjective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5
Objective Questions BCA Part III page 1 of 5 1. Java is purely object oriented and provides - a. Abstraction, inheritance b. Encapsulation, polymorphism c. Abstraction, polymorphism d. All of the above
More informationJAVA. Lab-9 : Inheritance
JAVA Prof. Navrati Saxena TA- Rochak Sachan Lab-9 : Inheritance Chapter Outline: 2 Inheritance Basic: Introduction Member Access and Inheritance Using super Creating a Multilevel Hierarchy Method Overriding
More informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More informationInheritance and Polymorphism
Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg
More informationJava Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing
Java Programming MSc Induction Tutorials 2011 Stefan Stafrace PhD Student Department of Computing s.stafrace@surrey.ac.uk 1 Tutorial Objectives This is an example based tutorial for students who want to
More informationDOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS
Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully
More informationA final method is a method which cannot be overridden by subclasses. A class that is declared final cannot be inherited.
final A final variable is a variable which can be initialized once and cannot be changed later. The compiler makes sure that you can do it only once. A final variable is often declared with static keyword
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More informationOOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.
OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
More informationJava Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.
Preface p. xix Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p. 5 Java Applets and Applications p. 5
More informationCS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70
CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 2012 OBJECT ORIENTED PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give their answers
More informationControl Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003
Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationInheritance and Polymorphism
Inheritance and Polymorphism Recitation 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University Project 5 Due Wed, Oct. 22 at 10 pm. All questions on the class newsgroup. Make use of lab
More informationDarshan Institute of Engineering & Technology for Diploma Studies Unit 3
Class A class is a template that specifies the attributes and behavior of things or objects. A class is a blueprint or prototype from which objects are created. A class is the implementation of an abstract
More informationJava. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)
Summary: Chapters 1 to 10 Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The University of Texas at Arlington, Arlington, TX 76019 Email: sharma@cse.uta.edu
More informationJava Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,
Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators, Expressions, Statements and Arrays. Java technology is: A programming
More informationSelf-review Questions
7Class Relationships 106 Chapter 7: Class Relationships Self-review Questions 7.1 How is association between classes implemented? An association between two classes is realized as a link between instance
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationChapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.
hapter 1 INTRODUTION SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Objectives You will learn: Java features. Java and its associated components. Features of a Java application and applet. Java data types. Java
More informationCH. 2 OBJECT-ORIENTED PROGRAMMING
CH. 2 OBJECT-ORIENTED PROGRAMMING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OBJECT-ORIENTED
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationJava Primer. CITS2200 Data Structures and Algorithms. Topic 2
CITS2200 Data Structures and Algorithms Topic 2 Java Primer Review of Java basics Primitive vs Reference Types Classes and Objects Class Hierarchies Interfaces Exceptions Reading: Lambert and Osborne,
More informationPOLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE
POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE COURSE NAME: OBJECT ORIENTED PROGRAMMING COURSE CODE: OOP521S NQF LEVEL: 6 DATE: NOVEMBER 2015 DURATION: 2 HOURS
More informationHierarchical inheritance: Contains one base class and multiple derived classes of the same base class.
1. What is C#? C# (pronounced "C sharp") is a simple, modern, object oriented, and type safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity
More informationChapter 5. Inheritance
Chapter 5 Inheritance Objectives Know the difference between Inheritance and aggregation Understand how inheritance is done in Java Learn polymorphism through Method Overriding Learn the keywords : super
More informationPaytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value
Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object
More informationChapter 14 Abstract Classes and Interfaces
Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden
More informationModule 10 Inheritance, Virtual Functions, and Polymorphism
Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:
More informationObject Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming
Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in
More informationChapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition
Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition 5.2 Q1: Counter-controlled repetition requires a. A control variable and initial value. b. A control variable
More informationCS1150 Principles of Computer Science Objects and Classes
CS1150 Principles of Computer Science Objects and Classes Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Object-Oriented Thinking Chapters 1-8
More informationFundamental Concepts and Definitions
Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most
More information( &% class MyClass { }
Recall! $! "" # ' ' )' %&! ( &% class MyClass { $ Individual things that differentiate one object from another Determine the appearance, state or qualities of objects Represents any variables needed for
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationJava provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationSelected Java Topics
Selected Java Topics Introduction Basic Types, Objects and Pointers Modifiers Abstract Classes and Interfaces Exceptions and Runtime Exceptions Static Variables and Static Methods Type Safe Constants Swings
More informationBasic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java
Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Selection
More informationOOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.
OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every
More informationJava Programming Training for Experienced Programmers (5 Days)
www.peaklearningllc.com Java Programming Training for Experienced Programmers (5 Days) This Java training course is intended for students with experience in a procedural or objectoriented language. It
More information204111: Computer and Programming
204111: Computer and Programming Week 4: Control Structures t Monchai Sopitkamon, Ph.D. Overview Types of control structures Using selection structure Using repetition structure Types of control ol structures
More informationWhat is Inheritance?
Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting
More informationVALLIAMMAI ENGINEERING COLLEGE
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED
More informationCMSC 331 Second Midterm Exam
1 20/ 2 80/ 331 First Midterm Exam 11 November 2003 3 20/ 4 40/ 5 10/ CMSC 331 Second Midterm Exam 6 15/ 7 15/ Name: Student ID#: 200/ You will have seventy-five (75) minutes to complete this closed book
More informationINHERITANCE. Spring 2019
INHERITANCE Spring 2019 INHERITANCE BASICS Inheritance is a technique that allows one class to be derived from another A derived class inherits all of the data and methods from the original class Suppose
More informationA Short Summary of Javali
A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler
More informationJava Control Statements
Java Control Statements An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/
More informationLecture 2: Java & Javadoc
Lecture 2: Java & Javadoc CS 62 Fall 2018 Alexandra Papoutsaki & William Devanny 1 Instance Variables or member variables or fields Declared in a class, but outside of any method, constructor or block
More information1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?
1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity
More informationObject Oriented Programming. Java-Lecture 11 Polymorphism
Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class
More informationC++ (Non for C Programmer) (BT307) 40 Hours
C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular
More informationCS 1316 Exam 1 Summer 2009
1 / 8 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1316 Exam 1 Summer 2009 Section/Problem
More informationComments are almost like C++
UMBC CMSC 331 Java Comments are almost like C++ The javadoc program generates HTML API documentation from the javadoc style comments in your code. /* This kind of comment can span multiple lines */ //
More informationBasics of Object Oriented Programming. Visit for more.
Chapter 4: Basics of Object Oriented Programming Informatics Practices Class XII (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra,
More information