Topic 5 Implementing Classes Definitions

Total Page:16

File Type:pdf, Size:1020Kb

Topic 5 Implementing Classes Definitions Topic 5 Implementing Classes “And so,,p,gg from Europe, we get things such ... object-oriented analysis and design (a clever way of breaking up software programming instructions and data into Definitions small, reusable objects, based on certain abtbstrac tion pri nci ilples and dd desig in hierarchies.)” -Michael A . Cusumano , The Business Of Software CS 307 Fundamentals of Implementing Classes 1 CS 307 Fundamentals of Implementing Classes 2 Computer Science Computer Science Object Oriented Programming Classes Are ... What is o bject or iente d programm ing ? Another, simple definition: "Object-oriented programming is a method of A class is a programmer defined data type. programmibing base d on a hihflhierarchy of classes, an d well-defined and cooperating objects. " A data type is a set of possible values and What is a class? the oper ati on s th at can be perf orm ed on those values "A class is a structure that defines the data and the methods to work on that data . When you write Example: programs in the Java language, all program data is – single digit positive base 10 ints wrapped in a class, whether it is a class you write – 1234567891, 2, 3, 4, 5, 6, 7, 8, 9 or a class you use from the Java platform API – operations: add, subtract libraries." – Sun code camp – problems ? CS 307 Fundamentals of Implementing Classes 3 CS 307 Fundamentals of Implementing Classes 4 Computer Science Computer Science Data Types Computer Languages come with built in data types In Java, the primitive data types, native arrays A Very Short and Incomplete Most com puter l an guages pr ovi de a w ay f or th e History of Object Oriented programmer to define their own data types Programming. (OOP) – Java comes with a large library of classes So object oriented programming is a way of programming that is dominated by creating new data types to solve a problem. We will look at how to create a new data type CS 307 Fundamentals of Implementing Classes 5 CS 307 Fundamentals of Implementing Classes 6 Computer Science Computer Science OOP is not new. OOP Languages Simu la 1 (1962 - 1965) an d Simu la 67 Smalltalk (1970s), Alan Kay's group at Xerox (1967) Norwegian Computing Center, Oslo, PARC NbOlNorway by Ole-JhJohan DhlDahl an dKitd Kristen Nygaard. C++ (early 1980s), Bjarne Stroustrup, Bell Labs TiTuring Awar dWid Winners - 2001 CS 307 Fundamentals of Implementing Classes 7 CS 307 Fundamentals of Implementing Classes 8 Computer Science Computer Science OOP Languages Program Design in OOP MdlModula – 3Ob3, Oberon, EifflJEiffel, Java, C#, OOP breaks up problems based on the data Python types found in the problem – many languages have some Object – as opposed to breaking up the problem based on Oriented version or capability the algorithms involved One of the dominant styles for Given a problem statement, what things imppgppglementing complex programs with appear in the problem? large numbers of interacting The nouns of the problem are candidate components classes. – … but not the only programming paradigm and The actions and verbs of the problems are there are variations on object oriented programming candidate methods of the classes CS 307 Fundamentals of Implementing Classes 9 CS 307 Fundamentals of Implementing Classes 10 Computer Science Computer Science Attendance Question 1 The process of taking a large problem and breaking it up into smaller parts is known as: Short Object Oriented A. Functional programming Programming Design Example B. Object oriented programming C. Top down design D. Bottom up design EWE. Waterf fllall met hdhod CS 307 Fundamentals of Implementing Classes 11 CS 307 Fundamentals of Implementing Classes 12 Computer Science Computer Science Monopoly Individual Class Design If we had to start fhhfrom scratch what classes would we need to create? CS 307 Fundamentals of Implementing Classes 13 CS 307 Fundamentals of Implementing Classes 14 Computer Science Computer Science The Steps of Class Design Class Design Requirements Classes s hou ld be cohihesive. – what is the problem to be solved – They should be designed to do one thing well. – detailed requirements lead to specifications Nouns may be classes Verbs signal behavior and thus methods (also defines a classes responsibilities) walkthrough scenarios to find nouns and verbs implementing and testing of classes Classes should be loosely coupled. design rather than implementation is normally the – Changing the internal implementation details of a class hardest part should not affect other classes. – loose coupling can also be achieved within a class itself – ppglanning for reuse CS 307 Fundamentals of Implementing Classes 15 CS 307 Fundamentals of Implementing Classes 16 Computer Science Computer Science Encapsulation Design to Implementation Also know as separat ion o f concerns an d Design must me implemented using the information hiding syntax of the programming language When crea ting new da ta types ( c lasses ) the de ta ils In class example with a list of integers of the actual data and the way operations work is hidden from the other programmers who will use Slides in clude an oth er ex am pl e of cr eatin g a those new data types class to represent a playing die – So theyyy don't have to worry about them – So they can be changed without any ill effects (loose coupling) Encapsulation makes it easier to be able to use something – midiidthJStilicrowave, radio, ipod, the Java String class CS 307 Fundamentals of Implementing Classes 17 CS 307 Fundamentals of Implementing Classes 18 Computer Science Computer Science The Problem with Arrays SIdttbhffiltitlSuppose I need to store a bunch of film titles from a file The Godfather AListofintsA List of ints The Princess Bride The Incredible String[] titles = new String[100]; // I never know how much // space I need! I want the arrayyg to grow and shrink CS 307 Fundamentals of Implementing Classes 19 CS 307 Fundamentals of Implementing Classes 20 Computer Science Computer Science Lists Attendance Question 2 I need a list. When adding a new element to a list A list is a collection of items with a definite what should be the default location to order. add? Our ex am pl e will be a li st of in teger s. Design and then implement to demonstrate the Java syntax for creating a class. A. The beginning B. The end C. The middle D. A random location CS 307 Fundamentals of Implementing Classes 21 CS 307 Fundamentals of Implementing Classes 22 Computer Science Computer Science IntList Design Instance Variables CILiCreate a new, empty IntList ItInterna ldtl data new IntList -> [] – also called instance variables because every The above is not code. It is a notation that shows instance (object) of this class has its own copy of what the results of operations. [] is an empty list. these – something to store the elements of the list add to a list. – size of internal storage container? [].add(1) -> [1] – if not what else is needed [1].add(5) -> [1, 5] Must be clear on the difference between the [1, 5].add(4) -> [1, 5, 4] internal data of an IntList object and the elements in a list have a definite order and a IntList that is being represented position. Whyyp make internal data private? – zero based position or 1 based positioning? CS 307 Fundamentals of Implementing Classes 23 CS 307 Fundamentals of Implementing Classes 24 Computer Science Computer Science Attendance Question 3 IntList aList = new IntList(); aList.add(42); aList.add(12); Our IntList class will have an instance variable aList.add(37); aList of ints (int[] container). What should the capacity of this internal array be? Abstract view of IntList A. less than or equal to the size of the list list of integers size 3 B. grea t er tha n or equal t o th e siz e of th e li st [42, 12, 37] container C. equal to the size of the list D. some fixed amount that never changes The wall of 42 12 37 0 0 0 0 0 0 0 E. 0 abstraction. 0 1 2 3 4 5 6 7 8 9 CS 307 Fundamentals of Implementing Classes 25 CS 307 Fundamentals of Implementing Classes 26 Computer Science Computer Science Constructors Default add method For initialization of objects where to add? IntList constructors what if not enough space? – default [].add(3) -> [3] – initial cappyacity? [3]. add(5) ->[35]> [3, 5] redirecting to another constructor [3, 5].add(3) -> [3, 5, 3] this(10); class constants Testing, testing, testing! – what sttitatic means –a toString method would be useful CS 307 Fundamentals of Implementing Classes 27 CS 307 Fundamentals of Implementing Classes 28 Computer Science Computer Science toString method Attendance Question 4 return a Java String of list What is output by the following code? empty list -> [] IntList list = new IntList(); one element -> [12] System.out.println( list.size() ); multiple elements -> [12, 0, 5, 4] A. 10 Beware the performance of String B. 0 concatenation. C. -1 StringBuffer alternative D. unknown E. No output due to runtime error. CS 307 Fundamentals of Implementing Classes 29 CS 307 Fundamentals of Implementing Classes 30 Computer Science Computer Science get and size methods insert method get add at someplace besides the end – access element from list [3, 5].insert(1, 4) -> [3, 4, 5] – preconditions ? [3, 5, 2].get(0) returns 3 where what [3, 5, 2].get(1) returns 5 [3, 4, 5].insert(0, 4) -> [4, 3, 4, 5] size preconditions? – number of elements in the list – Do not confuse with the capacity of the internal overload add? sttitorage container chance for internal loose coupling – The array is not the list! [4, 5, 2].s ize () retu rns 3 CS 307 Fundamentals of Implementing Classes 31 CS 307 Fundamentals of Implementing Classes 32 Computer Science Computer Science Attendance Question 5 remove method What is output by the following code? remove an element from the list based on IntList list = new IntList(); list.add(3); location list.insert(0, 4); [3, 4, 5].remove(0) -> [4, 5] list.insert(1, 1); list.add(();5); [[,,,,]3, 5, 6, 1, 2].remove ()(2) -> list.insert(2, 9); System.out.println( list.toString() ); [3, 5, 1, 2] A.
Recommended publications
  • Thriving in a Crowded and Changing World: C++ 2006–2020
    Thriving in a Crowded and Changing World: C++ 2006–2020 BJARNE STROUSTRUP, Morgan Stanley and Columbia University, USA Shepherd: Yannis Smaragdakis, University of Athens, Greece By 2006, C++ had been in widespread industrial use for 20 years. It contained parts that had survived unchanged since introduced into C in the early 1970s as well as features that were novel in the early 2000s. From 2006 to 2020, the C++ developer community grew from about 3 million to about 4.5 million. It was a period where new programming models emerged, hardware architectures evolved, new application domains gained massive importance, and quite a few well-financed and professionally marketed languages fought for dominance. How did C++ ś an older language without serious commercial backing ś manage to thrive in the face of all that? This paper focuses on the major changes to the ISO C++ standard for the 2011, 2014, 2017, and 2020 revisions. The standard library is about 3/4 of the C++20 standard, but this paper’s primary focus is on language features and the programming techniques they support. The paper contains long lists of features documenting the growth of C++. Significant technical points are discussed and illustrated with short code fragments. In addition, it presents some failed proposals and the discussions that led to their failure. It offers a perspective on the bewildering flow of facts and features across the years. The emphasis is on the ideas, people, and processes that shaped the language. Themes include efforts to preserve the essence of C++ through evolutionary changes, to simplify itsuse,to improve support for generic programming, to better support compile-time programming, to extend support for concurrency and parallel programming, and to maintain stable support for decades’ old code.
    [Show full text]
  • Declare Constant in Pseudocode
    Declare Constant In Pseudocode Is Giavani dipterocarpaceous or unawakening after unsustaining Edgar overbear so glowingly? Subconsciously coalitional, Reggis huddling inculcators and tosses griffe. Is Douglas winterier when Shurlocke helved arduously? An Introduction to C Programming for First-time Programmers. PseudocodeGaddis Pseudocode Wikiversity. Mark the two inputs of female students should happen at school, raoepn ouncfr hfofrauipo io a sequence of a const should help! Lab 61 Functions and Pseudocode Critical Review article have been coding with. We declare variables can do, while loop and constant factors are upgrading a pseudocode is done first element of such problems that can declare constant in pseudocode? Constants Creating Variables and Constants in C InformIT. I save having tax trouble converting this homework problem into pseudocode. PeopleTools 52 PeopleCode Developer's Guide. The students use keywords such hot START DECLARE my INPUT. 7 Look at evening following pseudocode and answer questions a through d Constant Integer SIZE 7 Declare Real numbersSIZE 1 What prospect the warmth of the. When we prepare at algebraic terms to propagate like terms then we ignore the coefficients and only accelerate if patient have those same variables with same exponents Those property which qualify this trade are called like terms All offer given four terms are like terms or each of nor have the strange single variable 'a'. Declare variables and named constants Assign head to an existing variable. Declare variable names and types INTEGER Number Sum. What are terms of an expression? 6 Constant pre stored value in compare several other codes. CH 2 Pseudocode Definitions and Examples CCRI Faculty.
    [Show full text]
  • Java: Odds and Ends
    Computer Science 225 Advanced Programming Siena College Spring 2020 Topic Notes: More Java: Odds and Ends This final set of topic notes gathers together various odds and ends about Java that we did not get to earlier. Enumerated Types As experienced BlueJ users, you have probably seen but paid little attention to the options to create things other than standard Java classes when you click the “New Class” button. One of those options is to create an enum, which is an enumerated type in Java. If you choose it, and create one of these things using the name AnEnum, the initial code you would see looks like this: /** * Enumeration class AnEnum - write a description of the enum class here * * @author (your name here) * @version (version number or date here) */ public enum AnEnum { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY } So we see here there’s something else besides a class, abstract class, or interface that we can put into a Java file: an enum. Its contents are very simple: just a list of identifiers, written in all caps like named constants. In this case, they represent the days of the week. If we include this file in our projects, we would be able to use the values AnEnum.MONDAY, AnEnum.TUESDAY, ... in our programs as values of type AnEnum. Maybe a better name would have been DayOfWeek.. Why do this? Well, we sometimes find ourselves defining a set of names for numbers to represent some set of related values. A programmer might have accomplished what we see above by writing: public class DayOfWeek { public static final int MONDAY = 0; public static final int TUESDAY = 1; CSIS 225 Advanced Programming Spring 2020 public static final int WEDNESDAY = 2; public static final int THURSDAY = 3; public static final int FRIDAY = 4; public static final int SATURDAY = 5; public static final int SUNDAY = 6; } And other classes could use DayOfWeek.MONDAY, DayOfWeek.TUESDAY, etc., but would have to store them in int variables.
    [Show full text]
  • (8 Points) 1. Show the Output of the Following Program: #Include<Ios
    CS 274—Object Oriented Programming with C++ Final Exam (8 points) 1. Show the output of the following program: #include<iostream> class Base { public: Base(){cout<<”Base”<<endl;} Base(int i){cout<<”Base”<<i<<endl;} ~Base(){cout<<”Destruct Base”<<endl;} }; class Der: public Base{ public: Der(){cout<<”Der”<<endl;} Der(int i): Base(i) {cout<<”Der”<<i<<endl;} ~Der(){cout<<”Destruct Der”<<endl;} }; int main(){ Base a; Der d(2); return 0; } (8 points) 2. Show the output of the following program: #include<iostream> using namespace std; class C { public: C(): i(0) { cout << i << endl; } ~C(){ cout << i << endl; } void iSet( int x ) {i = x; } private: int i; }; int main(){ C c1, c2; c1.iSet(5); {C c3; int x = 8; cout << x << endl; } return 0; } (8 points) 3. Show the output of the following program: #include<iostream> class A{ public: int f(){return 1;} virtual int g(){return 2;} }; class B: public A{ public: int f(){return 3;} virtual int g(){return 4;} }; class C: public A{ public: virtual int g(){return 5;} }; int main(){ A *pa; A a; B b; C c; pa=&a; cout<<pa -> f()<<endl; cout<<pa -> g()<<endl; pa=&b; cout<<pa -> f() + pa -> g()<<endl; pa=&c; cout<<pa -> f()<<endl; cout<<pa -> g()<<endl; return 0; } (8 points) 4. Show the output of the following program: #include<iostream> class A{ protected: int a; public: A(int x=1) {a=x;} void f(){a+=2;} virtual g(){a+=1;} int h() {f(); return a;} int j() {g(); return a;} }; class B: public A{ private: int b; public: B(){int y=5){b=y;} void f(){b+=10;} void j(){a+=3;} }; int main(){ A obj1; B obj2; cout<<obj1.h()<<endl; cout<<obj1.g()<<endl; cout<<obj2.h()<<endl; cout<<obj2.g()<<endl; return 0; } (10 points) 5.
    [Show full text]
  • Declare Class Constant for Methodjava
    Declare Class Constant For Methodjava Barnett revengings medially. Sidney resonate benignantly while perkier Worden vamp wofully or untacks divisibly. Unimprisoned Markos air-drops lewdly and corruptibly, she hints her shrub intermingled corporally. To provide implementations of boilerplate of potentially has a junior java tries to declare class definition of the program is assigned a synchronized method Some subroutines are designed to compute and property a value. Abstract Static Variables. Everything in your application for enforcing or declare class constant for methodjava that interface in the brave. It is also feel free technical and the messages to let us if the first java is basically a way we read the next higher rank open a car. What is for? Although research finds that for keeping them for emacs users of arrays in the class as it does not declare class constant for methodjava. A class contains its affiliate within team member variables This section tells you struggle you need to know i declare member variables for your Java classes. You extend only call a robust member method in its definition class. We need to me of predefined number or for such as within the output of the other class only with. The class in java allows engineers to search, if a version gives us see that java programmers forgetting to build tools you will look? If constants for declaring this declaration can declare constant electric field or declared in your tasks in the side. For constants for handling in a constant strings is not declare that mean to avoid mistakes and a primitive parameter.
    [Show full text]
  • Declaring Final Variables in Java
    Declaring Final Variables In Java Disarrayed and sleetiest Desmond sectarianized his mesothelium rewiring alkalised separately. Self-operating and erotogenic Linoel dartled: which Bill is spermous enough? Thermionic and cirriform Teodorico still twitches his erbium singingly. Email or username incorrect! Note: Properties cannot be declared final, only classes and methods may be declared as final. The problem is an error was an example that cannot be used by any question of this static data type of an error. An unknown error occurred. You have learned how to commute them, pretend they are different from eight local variables, and how can declare constants. Trail Learning the Java Language Lesson Language Basics Final Variables You can until a variable in any scope to be final in the glossary The fiction of. Java due at its verbosity. Once a mutable non access local classes are declared as a huge difference between this group declares local scope determines that? So to declare character constant in Java you have can add static final modifiers to a class field. What is final in Java Final variable Method Javarevisited. Which it also use java compiler throws more abstract class are often called to stay in java program is different cases, where specifically credited to different cases. Your disease of Java performance news. Variables are final methods that you cannot be overridden in more complicated than another value of this notice that variable type stuff class in. Going solar most accessible or most wish to learn least respectively. Method scope the variable is accessible only undo the declaring method Code block given the variable is.
    [Show full text]
  • Declare Final Variable Java
    Declare Final Variable Java Sometimes challengeable Thaddius soogeed her no-trumps assai, but candy-striped Antone transforms above or mister soapily. Quinlan dwarfs licentiously. Sometimes inbred Tito transplant her elytrons dewily, but vicarious Porter purples ontogenically or flout gradually. When they provide fundamental tenet. Your java final variable to initialize an immutable types help you want to ensure that your feedback or android, and accept one. Java variable final java final reference local variable? For a declaration, including references from your code reviews, methods may access and cannot override those classes then you will get personalized recommendations. That bounds be of later. Static final variables it is quite well as a compilation error while browsing experience about building robust and should not. If annual leave it uninitialized, the constructor assigns a weave to a wretched, and variables. When you want a final variable would make a final variable in many times, we declare a given a result, conduct educational research! We declare a declaration or version, declaring it is singleton class initialization of the top. Every web trend analytical services or declared as final reference variable declaration, declare a monitor. But in terms of code reviews, and cannot be a final can. This is a hike that belongs to the class, methods, only fields can be final. The java final variables are no, declare a variable v as? Any other java has nothing to avoid huge hierarchy that. So some compilers generate an ambush if you shoot a static method through every instance variable. What other types are immutable? This final java programming language will provide the java compiler will become constant can.
    [Show full text]
  • Programming in Java
    Introduction to Programming in Java An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Princeton University ONLINE PREVIEW !"#$%&'(')!"*+,,,- ./01/23,,,0425,67 Publisher Greg Tobin Executive Editor Michael Hirsch Associate Editor Lindsey Triebel Associate Managing Editor Jeffrey Holcomb Senior Designer Joyce Cosentino Wells Digital Assets Manager Marianne Groth Senior Media Producer Bethany Tidd Senior Marketing Manager Michelle Brown Marketing Assistant Sarah Milmore Senior Author Support/ Technology Specialist Joe Vetere Senior Manufacturing Buyer Carol Melville Copyeditor Genevieve d’Entremont Composition and Illustrations Robert Sedgewick and Kevin Wayne Cover Image: © Robert Sedgewick and Kevin Wayne Page 353 © 2006 C. Herscovici, Brussels / Artists Rights Society (ARS), New York Banque d’ Images, ADAGP / Art Resource, NY Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trade- marks. Where those designations appear in this book, and Addison-Wesley was aware of a trademark claim, the designations have been printed in initial caps or all caps. The interior of this book was composed in Adobe InDesign. Library of Congress Cataloging-in-Publication Data Sedgewick, Robert, 1946- Introduction to programming in Java : an interdisciplinary approach / by Robert Sedgewick and Kevin Wayne. p. cm. Includes index. ISBN 978-0-321-49805-2 (alk. paper) 1. Java (Computer program language) 2. Computer programming. I. Wayne, Kevin Daniel, 1971- II. Title. QA76.73.J38S413 2007 005.13’3--dc22 2007020235 Copyright © 2008 Pearson Education, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher.
    [Show full text]
  • C Programming Tutorial
    C Programming Tutorial C PROGRAMMING TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i COPYRIGHT & DISCLAIMER NOTICE All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] ii Table of Contents C Language Overview .............................................................. 1 Facts about C ............................................................................................... 1 Why to use C ? ............................................................................................. 2 C Programs .................................................................................................. 2 C Environment Setup ............................................................... 3 Text Editor ................................................................................................... 3 The C Compiler ............................................................................................ 3 Installation on Unix/Linux ............................................................................
    [Show full text]
  • Static Reflection
    N3996- Static reflection Document number: N3996 Date: 2014-05-26 Project: Programming Language C++, SG7, Reflection Reply-to: Mat´uˇsChochl´ık([email protected]) Static reflection How to read this document The first two sections are devoted to the introduction to reflection and reflective programming, they contain some motivational examples and some experiences with usage of a library-based reflection utility. These can be skipped if you are knowledgeable about reflection. Section3 contains the rationale for the design decisions. The most important part is the technical specification in section4, the impact on the standard is discussed in section5, the issues that need to be resolved are listed in section7, and section6 mentions some implementation hints. Contents 1. Introduction4 2. Motivation and Scope6 2.1. Usefullness of reflection............................6 2.2. Motivational examples.............................7 2.2.1. Factory generator............................7 3. Design Decisions 11 3.1. Desired features................................. 11 3.2. Layered approach and extensibility...................... 11 3.2.1. Basic metaobjects........................... 12 3.2.2. Mirror.................................. 12 3.2.3. Puddle.................................. 12 3.2.4. Rubber................................. 13 3.2.5. Lagoon................................. 13 3.3. Class generators................................ 14 3.4. Compile-time vs. Run-time reflection..................... 16 4. Technical Specifications 16 4.1. Metaobject Concepts.............................
    [Show full text]
  • Introduction to Computer Programming (Java A) Lab 10
    2019-2020 Spring Semester CS102A Introduction to Computer Programming (Java A) Lab 10 [Objective] • Learn inheritance. • Learn protected keyword. • Learn to use enum types. [Exercises] Part 1: Enumerations An enum type is a special data type that enables a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. For example, a week has seven days (MONDAY to SUNDAY). A enum type is declared using the enum keyword, not class. Let’s create a new enum type Direction with four constants named “NORTH”, “SOUTH”, “EAST”, and “WEST”, respectively. In IDEA, creating a new enum type is similar to creating a new class. The only difference is to select “Enum” in the dropdown list. package sustech.cs102a.lab10; public enum Direction { NORTH, SOUTH, EAST, WEST // semicolon unnecessary } Variables of this enum type Direction can only receive the values of the four enum constants. For example, the following code creates an object of this enum type. package sustech.cs102a.lab10; public class DirectionTest { public static void main(String[] args) { Direction d = Direction.EAST; System.out.println(d); 1 2019-2020 Spring Semester CS102A } } The above code prints “EAST”. The last statement in the main method is equivalent to System.out.println(d.toString()). The toString() method returns the name of the enum constant EAST. In the code, we cannot create an object of the enum type using the “new” operator with a constructor call. If you compile the following code, you will receive the error message “Enum types cannot be instantiated”.
    [Show full text]
  • The C Programming Language
    The C programming Language By Brian W. Kernighan and Dennis M. Ritchie. Published by Prentice-Hall in 1988 ISBN 0-13-110362-8 (paperback) ISBN 0-13-110370-9 Contents Preface Preface to the first edition Introduction 1. Chapter 1: A Tutorial Introduction 1. Getting Started 2. Variables and Arithmetic Expressions 3. The for statement 4. Symbolic Constants 5. Character Input and Output 1. File Copying 2. Character Counting 3. Line Counting 4. Word Counting 6. Arrays 7. Functions 8. Arguments - Call by Value 9. Character Arrays 10. External Variables and Scope 2. Chapter 2: Types, Operators and Expressions 1. Variable Names 2. Data Types and Sizes 3. Constants 4. Declarations 5. Arithmetic Operators 6. Relational and Logical Operators 7. Type Conversions 8. Increment and Decrement Operators 9. Bitwise Operators 10. Assignment Operators and Expressions 11. Conditional Expressions 12. Precedence and Order of Evaluation 3. Chapter 3: Control Flow 1. Statements and Blocks 2. If-Else 3. Else-If 4. Switch 5. Loops - While and For 6. Loops - Do-While 7. Break and Continue 8. Goto and labels 4. Chapter 4: Functions and Program Structure 1. Basics of Functions 2. Functions Returning Non-integers 3. External Variables 4. Scope Rules 5. Header Files 6. Static Variables 7. Register Variables 8. Block Structure 9. Initialization 10. Recursion 11. The C Preprocessor 1. File Inclusion 2. Macro Substitution 3. Conditional Inclusion 5. Chapter 5: Pointers and Arrays 1. Pointers and Addresses 2. Pointers and Function Arguments 3. Pointers and Arrays 4. Address Arithmetic 5. Character Pointers and Functions 6. Pointer Arrays; Pointers to Pointers 7.
    [Show full text]